0

So I want to capture one image, image s, which is always in the same region. It then disappears and may or may not re-appear in a different region.

I would like the program to capture the first time it appears and if it re-appears in the other region, then click a set of buttons otherwise move to a different function.

The other thing is image s changes each time the function is called but it remains in the same location.

Below is my code:

def playLoop():

s = capture(firstRegion)
warnBox = exists("1443867801301.png")
if not warnBox:
    if exists("1443867813008.png"):
        click(x)
        playLoop()
    else:
        if secondRegion.exists(Pattern(s).similar(0.8)):
            wait(3)
            click(x)
            playLoop()
        else:
            loopLoop()
else:
    doubleClick(y)
    if secondRegion.exists(Pattern(s).similar(0.8)):
            wait(3)
            click(x)
            playLoop()
    else:            
        loopLoop()

I get no errors, however it doesn't seem to work. Any ideas?

codeav33
  • 1
  • 2
  • I think that you program is already finished before the given image has a chance to appear in another reagion. Have a look at `while not exists`. – Tenzin Oct 22 '15 at 08:42

2 Answers2

1
  1. I think you should change this:
    s = Screen.capture(firstRegion)
    for this:
    s = capture(firstRegion)
  2. You can get the coordinates with find(image):
    f = find(s)
    x = getX()
    y = getY()
  3. Finally, if you want to get the numer of times, you can pass a variable to the function:

    def playLoop(times,x,y):
    
        s = capture(firstRegion)
        t = find(s)
        if times==0:
            warnBox = exists("1443867801301.png")
            if not warnBox:
                if exists("1443867813008.png"):
                    click(x)
                    times+=1
                    playLoop(times,t.getX(),t.getY())
        if times != 0:
            warnBox = exists("1443867801301.png")
            if not warnBox:
                if t.getX() != x or t.getY() != y: #different location
                    doSomething()
                else:
                    otherFunction() #same location
                times+=1
    

    PD: Sry if my english isn't good :)

Michael Becerra
  • 401
  • 1
  • 3
  • 15
  • I have followed your first suggestion however, I am not really interested in getting the co-ordinates. All I would like is for the function to capture the first region and then when required see if the image captured exists in the second region. I have updated my code and question. Thanks for your help though :) – codeav33 Oct 07 '15 at 14:17
0

To see if region1 exists in region2 you could use if region2.exists(region1) then.

Tenzin
  • 2,415
  • 2
  • 23
  • 36