Dealing with Multiple onAppear images using background observe and region

Asked by DAVID MASTROIANNI on 2017-10-17

Settings.MoveMouseDelay = 0.05
def Battle(evt):
    InAction = True
    print("Found Battle Button")
    click("1508195786538.png")
    wait("1508195823256.png", FOREVER); click();wait(1)
    HoverForMove()
    evt.repeat()

def NextButton(evt):
    InAction = True
    print("Found Next Button")
    click("1508200678194.png");wait(1)
    HoverForMove()
    evt.repeat()

def MapNext(evt):
    InAction = True
    click(Pattern("1508200450289.png").similar(0.80));wait(1)
    HoverForMove()
    evt.repeat()

def EndGame(evt):
    running = False

def HoverForMove():
    print("Hovering Search")
    hover(Pattern("1507123087352-1.png").targetOffset(-217,-356));wait(1)
    InAction = False

reg = Region(560,0,560,1050)
reg.onAppear("1508195786538.png",Battle)
reg.onAppear(Pattern("1508200450289.png").similar(0.80),MapNext)
reg.onAppear("1508200678194.png",NextButton)
reg.onAppear(Pattern("1507126043448-1.png").similar(0.96).targetOffset(-12,92),EndGame)
reg.observe(FOREVER,True)

print("Starting Loop")
running = True
InAction = False
HoverForMove()
while (running):
    if(not InAction):
        mouseDown(Button.LEFT)
        mouseUp(Button.LEFT)
    wait(.33)
exit
===============================================================================
The problem is it only registers the first reg.onAppear which references a battle button
===============================================================================
reg = Region(560,0,560,1050)
reg.onAppear("1508195786538.png",Battle)
reg = Region(560,0,560,1050)
reg.onAppear(Pattern("1508200450289.png").similar(0.80),MapNext)
reg = Region(560,0,560,1050)
reg.onAppear("1508200678194.png",NextButton)
reg = Region(560,0,560,1050)
reg.onAppear(Pattern("1507126043448-1.png").similar(0.96).targetOffset(-12,92),EndGame)
reg = Region(560,0,560,1050)
reg.observe(FOREVER,True)

also does not work

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
DAVID MASTROIANNI
Solved:
2017-10-18
Last query:
2017-10-18
Last reply:
2017-10-17
RaiMan (raimund-hocke) said : #1

in the def's you have to add
global InAction
as first line

to tell Python, that inAction is the variable in the global scope.

in Python a def has its own variable scope.

DAVID MASTROIANNI (dmastro918) said : #2

Beautiful!
Thank you so much for the reply!