2014-09-20 149 views
0

我想在def'UseCaps'上重复5秒钟。例如,5秒钟后,重复进行高清“UseCaps”,然后在5秒后再次等重复进行...定时器,倒计时,时间

下面是代码:

def Mobber(self): 
    global Mobber 

    if Mobber == 0: 
     Mobber = 1 

     self.EnableMobber() #Jump to EnableMobber 

    else: 
     Mobber = 0 
     self.DisableMobber()  

def EnableMobber(self): 
    self.MobberButton.SetText("Deactivate") 
    self.time.EditLineDelayTime.GetText()) 
    self.UseCape() 

def UseCape(self): 
    for i in xrange(player.INVENTORY_PAGE_SIZE*3): 
     BraveryCape = player.GetItemIndex(i) 
     if BraveryCape == 70038: 
      net.SendItemUsePacket(i) 
      break 

我一直在使用的时间尝试。睡觉。

+0

我在代码中的任何地方都看不到'time.sleep' ... – MattDMo 2014-09-20 21:31:05

+0

我在最后一个def的休息后使用了它。但没有工作,我删除它。 – bobi 2014-09-20 21:34:15

+1

如果您需要编写代码的帮助,则需要在代码中包含该代码,即使该代码不工作。这就是调试的工作原理。 – MattDMo 2014-09-20 21:37:20

回答

1

我写了一个具有每5秒钟执行一次的函数的类。我使用了一个while循环和模块化算术。

import time 
class The_Class(): 
    def __init__(self): 
     self.counter=0; 


    def some_function(self,counter): 
     x="I am a function, doing things!" 
     if self.counter%2 == 0: # if i is even do uppercase 
      return x.upper() 
     else:     #(here self.counter%2 ==1 and is odd so do lowercase) 
      return x.lower() 

    def a_while_loop(self): 
     while 1==1: #so this loop goes on and on because this is always true. 
      time.sleep(5) 
      print self.some_function(self.counter) 
      self.counter+=1 



the_class=The_Class() 
the_class.a_while_loop() 
+0

感谢您的回复!我现在就试试这个 – bobi 2014-09-20 23:52:34