← Back to team overview

sikuli-driver team mailing list archive

[Question #686822]: creating a timer in sikuli, need updrate from old code.

 

New question #686822 on Sikuli:
https://answers.launchpad.net/sikuli/+question/686822

Hello, i was looking for a timer that i could use, i found the 2012 post https://answers.launchpad.net/sikuli/+question/211455 and the code raiman used on post#8 seemed like what i need but ia can't seem to get it to work.

here is my code:
#Timers
common ="common.png"
rare ="rare.png"
brare ="brare.png"
tresure ="tresure.png"

Settings.timer =time.time()
start = time.time()
runn =True


def stop(event):
    global runn
    runn =False
Env.addHotkey(Key.F1,KeyModifier.ALT, stop)

def timer(name, elapse=0):
    if elapse >0:
        exec(Settings.timer+ str(1) + "=time.time()+" + str(elapse))
    else:
        rest =eval(Settings.timer + str(1)) - time.time()
        if rest >0:
            return False
        else:
            return True
        
while runn:
    print "counting"
    if timer(1,2):
        print"timer1"
    elif exists(rare):
        timer(2,4)
    elif exists(brare):
        timer(3,6)
    else:
        pass
    
    while timer() and runn:
        click(tresure)
        print"waiting"

print "Elapsed: %d seconds"%(int(time.time()-start))

The error it is giving me is:
error] TypeError ( unsupported operand type(s) for +: 'float' and 'str' )
[error] --- Traceback --- error source first
line: module ( function ) statement 
18: main (  timer )     exec(Settings.timer+ str(1) + "=time.time()+" + str(elapse))
27: main (  <module> )     if timer(1,2):

really appreciate the help.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.