not correct work of operator IF

Asked by olegbrest

v.1.1.1 win10 x64

in this line ( if ((checkdock()==1) and (checkenemy()==0)): ) IF work as While. Doing only checkdock() and not trying to checkenemy() while checkdock()!=1

code:

def checkdock():
    if (stationreg.inside().exists(undock,0.5)):
        docked=1
        print "в доке"
    else:
        docked=0
        print "не в доке"
    return docked

def checkenemy():
    if ((local.inside().exists(vrag1,0.5)) or( local.inside().exists(vrag2,0.5)) or (local.inside().exists(vrag3,0.5))):
        enemy=1
        print "есть вражина"
    else:
        enemy=0
        print "всё чисто"
    return enemy

while True:
    if ((checkdock()==1) and (checkenemy()==0)):
        print "ща андокнусь"
        stationreg.inside().click(undock)
        sleep (5)
 while (checkenemy() == 0):
  keyDown(Key.ALT)
  type("p")
  keyUp(Key.ALT)
  sleep (15)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
olegbrest
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#2

--1. inside()
... is redundant and no longer needed

stationreg.inside().exists(undock,0.5)

should be
stationreg.exists(undock,0.5)

Revision history for this message
RaiMan (raimund-hocke) said :
#3

--- using if ((checkdock()==1) and (checkenemy()==0)):
then this is according to the Python eval rules:
In <a and b>, if a is False, then b is never evaluated.

Revision history for this message
olegbrest (pop457045) said :
#4

the problem was resolved, restart IDE. Now everything works fine with the same code