I want to make "if" statement inside the first "if" statement and it just didn't detect anything from condition. Help.

Asked by Parsawit Deshwattanatham on 2019-07-23

Ok, so I am not a programmer. I self-study and learn a little bit, not much.

-Sikulix version 1.1.4 SNAPSHOT-

So my problem is I want to put another "if" inside the first "if" statement but it seems like sikulix just ignored it? I don't get any error but it skipped to "else" instead I really have no clue and I tried to solve this problem by myself for 3 days and haven't figured it out yet.

here my script:
++++++++++++++++++++++++++++++++
import random
running = True

while running:
     wait(1.5)
     if Region(722,262,91,117).exists("Idle.png" or Pattern("cautionwarning.png").similar(0.50), 0.5):
          type("s")
          if Region(626,283,249,26).exists("1563896526299-1.png", 0.5):
               type(Key.TAB)
               type("Well I am joking its not")
               type(Key.ENTER)
          else:
               wait(5)
          Settings.WaitScanRate = 9
          Region(741,437,58,34).wait(Pattern("1563771733509.png").similar(0.75), 10)
          Settings.WaitScanRate = 9
          Region(719,438,61,29).waitVanish(Pattern("1563771733509.png").similar(0.75), 60)
          type("s")
          sleep(1)
          keyDown(Key.DOWN)
          sleep(1)
          keyUp(Key.DOWN)

     else:
          type(Key.TAB)
          word = random.choice(["lol", "wtf","Wossshh", "Bruhhh", "......", "Hm", "showfishlevel", "YEEET"])
          type(word)
          type(Key.ENTER)
          wait(1)
          keyDown(Key.UP)
          wait(1)
          keyUp(Key.UP)
          keyDown(Key.LEFT)
          wait(5)
          keyUp(Key.LEFT)
          keyDown(Key.RIGHT)
          Settings.WaitScanRate = 9
          Region(735,264,73,118).wait(Pattern("1563778771909.png").similar(0.59) or Pattern("1563802583998.png").similar(0.58), 10)
          keyUp(Key.RIGHT)
          keyDown(Key.DOWN)
          wait(1)
          keyUp(Key.DOWN)

I tested it and it just ignored or didn't see "Idle.png" or "cautionwarning.png"

but if I remove

          if Region(626,283,249,26).exists("1563896526299-1.png", 0.5):
               type(Key.TAB)
               type("Well I am joking its not")
               type(Key.ENTER)
          else:
               wait(5)

it will work properly I really don't know why! Please help!

Best Regards

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2019-07-23
Last query:
2019-07-23
Last reply:
2019-07-23
Best Manfred Hampl (m-hampl) said : #1

The expression
Region(722,262,91,117).exists("Idle.png" or Pattern("cautionwarning.png").similar(0.50), 0.5)
is invalid.

exists(...) needs a pattern object, or a string as first paramater.
Your text "Idle.png" or Pattern("cautionwarning.png").similar(0.50)
is neither a pattern object, nor a string, but a logical expression.

You need to formulate it differently, probably something like

if Region(722,262,91,117).has("Idle.png", 0.5) or Region(722,262,91,117).has(Pattern("cautionwarning.png").similar(0.50), 0.5):

see also https://sikulix-2014.readthedocs.io/en/latest/region.html

Hi Manfred!

  First, thanks for replying. I really appreciate your help! I tried that and it seems to be right somehow. I will try something that I have problems with! I will keep updating.

Well, thanks! it seems like your solution helps me solve the problem!

Thank you Manfred!