我想在def' UseCaps'上重复5秒钟。例如,在5秒后,它会重复def' UseCaps'然后在5秒后它再次重复def,依此类推......
以下是代码:
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
我尝试过使用time.sleep。
答案 0 :(得分: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()