Number recognition

Asked by Eric G

I'm currently using region.text() feature to get various numbers from my screen. They're usually accurate enough, however is it possible to have sikuli perform actions based on what these number values are?
For ex. if region.text() < 1000 click(some img) if >1000 click (some other img)

Is that possible? If so please let me know how

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
Best Manfred Hampl (m-hampl) said :
#1

region.text() returns a string. If you want to compare that with a number, you have to convert the string to a number first.

myValue = int(region.text())
if myValue < 1000:
   #do this
else:
   #do that

(Remark, if region.text returns a non-numeric string, then int(...) will fail with ValueError unless you put it into a try - except.)

Revision history for this message
Eric G (gamemaster181) said :
#2

Wait that is so incredibly helpful

I can't thank you enough for answering my beginner question, you're awesome

Revision history for this message
Eric G (gamemaster181) said :
#3

Thanks Manfred Hampl, that solved my question.