计时器,倒计时,蒂姆

2024-06-26 13:42:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在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

我试过使用时间。睡眠. 你知道吗


Tags: to代码selfifdefglobalelseplayer
1条回答
网友
1楼 · 发布于 2024-06-26 13:42:30

我写了一个类,它有一个每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()

相关问题 更多 >