Jump to content
  • 0

Timer on python


Sober

Question

Guys i am trying to figure out how to do a timer on metin2 client.

i use the function

time.sleep(3)

but the client freezes for 3 seconds xD Any ideas on how to do it without freezing?

Link to comment

18 answers to this question

Recommended Posts

  • 0
global name 'timer' is not defined

I get this error when i try these.

		t = timer(3.0,__hideKillsGuiBg)
		t.start()

I tried: from threading import Timer

but i get an error : there isn't any module called threading 

Link to comment
  • 0

i don't have anything named threading.pyc or something like that in the libs , how can i import it?? Does it need any change on the binary?

Link to comment
  • 0

I found a threading.pyc in the lib folder but i get the error bad magic number.I think the lib was for python2.6 but my client uses python2.7 Could someone please give me the threading.pyc for 2.7? :P

Link to comment
  • 0

Guys, what about use new thread for sleep so game will not freeze? xD

[codesyntax]

import thread

import app

import chat

 

def test():

 app.Sleep(3000) # 3 seconds

 chat.AppendChat(chat.CHAT_TYPE_INFO, "hello world")

 

thread.start_new_thread(msg, ())

[/codesyntax]

Enough is enough

Link to comment
  • 0
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 "======================================================"

maybe you could work on your business

 

Best Regards

Aveline

  • Love 1

Plain logic saves lives.

Link to comment
  • 0
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 "======================================================"

maybe you could work on your business

 

Best Regards

Aveline

 

There is no need to make that, he can simply write this:

define a variable for your action, for example you whant to make a timer when you buy.
When you buy a thing you define sothing like this:
self.buytime = app.GetTime()

and then you whant to wait like 30 seconds before you can buy, you can write this:

import time
if app.GetTime() < self.buytime+30:
               code the part when the timer is running
else:
            after timer stopped
            Here you make a action so he can buy again.
Link to comment
  • 0

You are wrong because with the if statement it's checks only once,you need to use while loop

But i was talking if he was working with action, like for example chat action, whennever you talk that if executes.

Link to comment
  • 0

There is a simple way:

def myfunction_took_long_to_execute():
     for i in range(500000000000000000000000000000000000):
          print i
     return i
def myfunction_took_long_to_execute_with_yield():
     for i in range(500000000000000000000000000000000000):
          print i
          yield None
     return i

 

https://docs.python.org/release/2.5.2/ref/yield.html

 

I would post a better example, but Ymir Client times are long ago...

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

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.