Alan Carlos Lopez
Alan Carlos Lopez

Reputation: 19

Store a value and compare it with a new one

I'm working in a python script runner and I've been trying to find a way to store a value and then compare itself after a few seconds. This is my code so far :

  initialexp = game.GetCharEXP()
    print initialexp

import time
print 'Waiting 5 seconds to check changes on Initial EXP'
time.sleep(5)

if initialexp == final exp:
    exit()

game.GetCharEXP() is a function included in the software (when I print it it shows the value).

exit() is another function included in the script runner.

so, what I want is store game.GetcharEXP() value into initialexp and then compare it 5 seconds later with finalexp variable and make a loop of it (so it checks it every 5 seconds).

Upvotes: 0

Views: 1280

Answers (2)

Steve O'Driscoll
Steve O'Driscoll

Reputation: 446

import time
while True:
    initialexp = game.GetCharEXP()
    time.sleep(5)
    if initialexp == game.GetCharEXP():
        # Exp did not change within 5 seconds so perform an action

Upvotes: 0

dmargol1
dmargol1

Reputation: 415

You could just create a while loop and then break out of it when the values match.

import time
while 1:
    time.sleep(5)
    if initialexp == finalexp:
        break

Upvotes: 2

Related Questions