我有一个内部带有标签的对话框,每次打印一个单词。所有这些都是在点击游戏中的对象时调用的。
一旦点击了对象,我就创建了一个名为blockclick
的标志,等于True
。对话框完成打印后,blockclick=False
。我试图这样做,以便在blockclick == True
时,点击对象不会重新打开对话框或重置它,但这正是发生了什么,我不确定我做错了什么。
我意识到我的代码可能难以理解(我不是最好的程序员),但希望你能看到我正在尝试用blockclick
做什么。
底部的treetext
函数是我猜测问题所在的位置(如果blockclick==False
,请执行所有操作。)
class DialogueLabel(ButtonBehavior, Label):
def __init__(self, **kwargs):
super(DialogueLabel, self).__init__(**kwargs)
self.text2="empty string"
self.font_name='fonts/PressStart2P.ttf'
self.font_size=16
self.halign='center'
self.text_size=(Window.width*.75, Window.height*.25)
self.mipmp = True
self.line_height=2.5
self.center_x=(Window.width/2)
self.center_y=(Window.height/5)
self.markup = True
self.counter=0
self.blockclick=False
def example(self, *args):
self.counter += 1
self.blockclick=True
anim = Animation(pos_hint= {'top': .31}, duration=.3)
anim.start(messagebox)
if len(words) > self.counter:
self.text += words[self.counter] #might need to be self.counter-1
self.text += " "
elif len(words) < self.counter:
Clock.schedule_once(self.closeanimation, 3.5)
Clock.schedule_once(self.cleartext, 3.5)
Clock.schedule_once(lambda dt: messagebox.dismiss(), 4)
Clock.schedule_once(self.unlock, 3)
return False
def lock(self, dt):
self.blockclick=False
def closeanimation(self, dt):
anim2 = Animation(pos_hint= {'top': .0}, duration=.3)
anim2.start(messagebox)
def cleartext(self, dt):
self.text=""
newmessage=DialogeLabel
def treetext(*args):
if newmessage.blockclick==False:
newmessage.text=''
newmessage.counter=-1
newmessage.text2= "You ran into a tree. You are a moron"
messagebox.open()
global words
words=newmessage.text2.split(" ")
Clock.schedule_interval(newmessage.example, .2)
else:
pass