Delay between Python Code

12/28/2022 14:28 OnlyGood#1
How can i make a simple sleep function with python, without freezing the metin client?
12/28/2022 23:40 .Daklyrus#2
Does the following method make it freeze?

Code:
from time import sleep

sleep(x)
x = sleep time in seconds
12/29/2022 12:50 OnlyGood#3
Quote:
Originally Posted by .Daklyrus View Post
Does the following method make it freeze?

Code:
from time import sleep

sleep(x)
x = sleep time in seconds
yes, sleep makes it freeze
01/02/2023 18:24 martinx1#4
My recommendation here is to create a new window, inherit from ui.ScriptWindow and then overwrite the OnUpdate method, this particular function will be run by the engine for every logic update cycle, you can leverage this to be used like a thread.
[Only registered and activated users can see links. Click Here To Register...]
01/03/2023 11:07 Almanyo#5
Either use a thread from threading module or use the mainloop of OnRender or OnUpdate like martinx1 said, but there you have to simulate the "sleep logic" by checking the current time(stamp).
01/05/2023 09:40 Endless.#6
OnlyGood, try your function link with Thread
01/06/2023 21:32 martinx1#7
I wouldn't advise on using the threading module. The game was desgined to be single thread, if you spawn another thread you might run into race conditions and thus get random crashes.
01/10/2023 17:10 Endless.#8
Quote:
Originally Posted by martinx1 View Post
I wouldn't advise on using the threading module. The game was desgined to be single thread, if you spawn another thread you might run into race conditions and thus get random crashes.
Its not possible to set a time.sleep(delay) without crash or freezing?

then i can prefer only this solution:

Code:
if app.GetTime() < timeyouwant:
               code the part when the timer is running
else
            after timer stopped
or

Code:
def SetSleepFunction(self, time):
	self.function_sleep_time = app.GetGlobalTimeStamp() + time
    
def OnUpdate(self):
	if self.function_sleep_time and self.function_sleep_time < app.GetGlobalTimeStamp():
		self.function_sleep_time = None
        	# Your action
Its from another Forum, because the most People have Problems with them.


Best Regards, Endless.