Number recognition

Asked by Eric G on 2020-02-26

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:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2020-02-26
Last query:
2020-02-26
Last reply:
2020-02-26
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.)

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

Eric G (gamemaster181) said : #3

Thanks Manfred Hampl, that solved my question.