Jump to content

Recommended Posts

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 https://metin2.dev/board/index.php?/topic/1264-timer-on-python/  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!

?

Link to comment
https://metin2.dev/topic/22777-while-loop-timer-between-functions/
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.