Hi! I'm trying to call multiple functions with a certain delay between them, something like this:
def AllMightyFunction():
global Min
while (x>Min):
Function_1()
Wait(1 sec)
Function_2()
Wait(1 sec)
Function_3()
Wait(1 sec)
Function "AllMightyFunction" is executed when i press a certain button. So i need to have 2 buttons: 1 for this function and 1 for when i want to stop the while loop.
What i've tried so far: with a little help from this thread [Hidden Content] i've managed to make the function runs only one time. I use the class "Wait" posted by @AvelineTM.
import time
class Wait(ui.ScriptWindow):
def __init__(self):
ui.ScriptWindow.__init__(self)
self.eventTimeOver = lambda * arg: None
self.eventExit = lambda * arg: None
def __del__(self):
ui.ScriptWindow.__del__(self)
def Open(self,waitTime):
curTime = time.clock()
self.endTime = curTime + waitTime
self.Show()
def Close(self):
self.Hide()
def Destroy(self):
self.Hide()
def EmptyFunc(self):
pass
def SAFE_SetTimeOverEvent(self,event = 0):
if(not event):
self.eventTimeOver = self.EmptyFunc
self.eventTimeOver = ui.__mem_func__(event)
def SAFE_SetExitEvent(self,event = 0):
if(not event):
self.eventExit = self.EmptyFunc
self.eventExit = ui.__mem_func__(event)
def OnUpdate(self):
lastTime = max(0,self.endTime - time.clock())
if(lastTime == 0):
self.Close()
else:
return
def OnPressExitKey(self):
self.Close()
return True
## Example ;
self.waitFor = Wait()
self.waitFor.Open(20.0)
self.waitFor.SAFE_SetTimeOverEvent(self.SecondFinished)
self.waitFor.SAFE_SetExitEvent(self.ExitKey)
def SecondFinished(self):
print "======================================================"
print "Second is finished."
print "======================================================"
def ExitKey(self):
print "======================================================"
print "Exit Key -- Write Something"
print "======================================================"
If i use while statement, game freeze. If i use OnUpdate() + something like in Example part, the function do nothing.
def AllMightyFunction(self):
# here should be a while loop
self.WaitTimeBuy = Wait()
self.WaitTimeBuy.Open(0.1)
self.WaitTimeBuy.SAFE_SetTimeOverEvent(self.Buy)
self.WaitTimeOpen = Wait()
self.WaitTimeOpen.Open(0.5)
self.WaitTimeOpen.SAFE_SetTimeOverEvent(self.Open)
self.WaitTimeSell = Wait()
self.WaitTimeSell.Open(1.0)
self.WaitTimeSell.SAFE_SetTimeOverEvent(self.Sell)
I know this should be something easy but i can't figure it out.
Thanks in advance!
?