繁体   English   中英

计时器,倒数计时,时间

[英]Timer, countdown, time

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM