← Back to team overview

sikuli-driver team mailing list archive

[Question #406532]: cant temporarily stop event observations

 

New question #406532 on Sikuli:
https://answers.launchpad.net/sikuli/+question/406532

Hi,

    I'm trying to automate a game on facebook by setting an observe region. The game is quite simple. eggs drop from the top of the screen and all you have to do is catch them at the bottom of the screen. The glove that catches them its move by the mouse. All the eggs have the same shape and size but they all have different design patterns so I can't do a search for a particular egg since all of them are different and the design appears randomly. Plus there must be thousands of designs. 

So here is what I did:
    I set up a rectangular region across the screen close to the glove. I then set up an regionX.onchage event. Once an egg crosses that region the glove is put underneath it. This is not a perfect solution because you can get multiple hits so the glove tends to jump around but, its good enough. The problem is that once you collect 100 eggs a button at the bottom of the screen shows up. You need to click that button and navigate through some menus to collect some of the eggs and ignore others. Here is where I'm having problems. It seems that the regionX.onchange keeps running so I can't navigate through this menu. I need for the program to stop searching for changes completely until I exit the egg collection menu. Below is part of the code. I'm omiting the searches for other buttons since they are commented out (not being used for now) anyways.

#settings
Settings.ObserveScanRate = 0.4
Settings.ObserveMinChangedPixels = 65

#globals
runGame = True


#define regions
regionX = Region(261,453,813,26)  #look for changes 
regionA = Region(585,629,165,62)  #start game button region
regionB = Region(589,538,166,79)  #keep playing region
regionC =Region(562,532,251,144)  #bag full
regionD =Region(478,298,503,384)  #rare eggs


#Set the observations
regionX.onChange(FOREVER, onchangedFunction)



#define pertinent functions
#Move glove to collect the eggs
def onchangedFunction(event):
    regionX.stopObserver()    #<--- stop event temporarily

    for ch in event.getChanges(): 
        hover(Location(ch.x+10, ch.y))
        wait(0.4)

    regionX.onChange(onchangedFunction)      #<-- restore egg search event
    regionX.observe(FOREVER, background=True)


#get the rarest eggs  
def getRareEggs():
    regionD.wait(Pattern("1467043168899.png").targetOffset(-320,3), 10)

    while regionD.exists(Pattern("1467043168899.png").targetOffset(-320,3), 0):     
        click(regionD.getLastMatch())  # avoids another find() operation
        wheel(WHEEL_DOWN, 1)
        wait(0.8)

    regionD.click("1480910851742.png") 
    wait(0.8)



#-----RUN GAME------
while(runGame):
    #Check if 100 eggs have been collected
    if regionC.exists("1481068803504.png"):
        regionX.stopObserver()   #<-- Does this stops observations???
        regionC.click(regionC.getLastMatch()) # avoids another find() operation
        wait(3)
        getRareEggs()
        wait(1)
        regionX.onChange(onchangedFunction)  #<-- restore observations 
        regionX.observe(FOREVER, background=True)


-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.