-1

I am trying to make my script end the loop or exit if a certain image appears inside certain region.

I get an error when I run the script; I am not sure what is wrong as the parts about stopregion and stopimage were advised by another person.

The error:

[error] TypeError ( 'tuple' object is not callable )

My code is below:

Image1 = ("1453735625632-12.png")
Image2 = ("1453723117924-16.png")
stopRegion = (815,423,314,136)
stopImage = ("1454946335394.png")
while True:
click(wait("1453202630435-1.png",FOREVER))      
if stopRegion.exists("1454946335394.png", 0): # ends in error
    break 
click(wait("1453994048404-9.png",FOREVER)) 
click(wait("1453202812250-3.png",FOREVER)) 
while True:
    print('Searching....')
    if exists("1453723117924-17.png", 0):        
        click("1453723117924-18.png")
        # Break loop.
        break
    if exists("1453735625632-14.png", 0):
        click("1453735625632-15.png")
        # Break loop.
        break
click(wait("1453202882292-7.png",FOREVER)) 

Any help is much appreciated.

Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
Drake14
  • 3
  • 2
  • does the exists() fcn even work in python? whenever i look up how to check if a variable exists it says to check in locals() or globals(). – Jeremy Fisher Feb 10 '16 at 16:27

1 Answers1

0

I think the problem is

stopRegion = (815,423,314,136)               # this is a tuple, not a Region

stopRegion.exists("1454946335394.png", 0)    # a tuple does not have an .exists method

Try instead

stopRegion = Region(815,423,314,136)

You also need to fix your indentation, and I suggest more meaningful names for the images, something like

BUTTON1         = "1453994048404-9.png"
BUTTON2         = "1453202812250-3.png"
RESULT_A        = "1453723117924-17.png"
RESULT_A_BUTTON = "1453723117924-18.png"
RESULT_B        = "1453735625632-14.png"
RESULT_B_BUTTON = "1453735625632-15.png"
START           = "1453202630435-1.png"
STOP            = "1454946335394.png"
FINISHED        = "1453202882292-7.png"

stop_region = Region(815,423,314,136)

done = False
while not done:
    print("Starting search")
    click(wait(START, FOREVER))
    if stop_region.exists(STOP, 0):
        print("Found STOP")
        break
    click(wait(BUTTON1, FOREVER)) 
    click(wait(BUTTON2, FOREVER)) 

    while True:
        print('Searching....')

        if exists(RESULT_A, 0):        
            print("Found RESULT_A")
            click(RESULT_A_BUTTON)
            # finished searching
            done = True     # set flag to exit outer while loop
            break           # leave inner while loop

        if exists(RESULT_B, 0):
            print("Found RESULT_B")
            click(RESULT_B_BUTTON)
            # go to next search
            break           # leave inner while loop but not outer one

click(wait(FINISHED, FOREVER)) 
Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
  • Thank you i didn't know i can assign names to the images much cleaner now but the region is still being ignored even when the image shows up also the new code don't have a loop anymore it ends at finished instead of looping back to start like mine did is there any way i can add back the loop? i know it involves a while TRUE somewhere but not sure where to insert it, also since the stop image is not working will a stop text work instead? as in if a certain word appears in the region in place of the image – Drake14 Feb 11 '16 at 15:20
  • I took your advise and changed the region codes so it points to region instead of tuple no errors but region not recognized either until changed the 0 in if stopregion.exists(stop_Image 0): to FOREVER as a test and for the first time it recognized and stopped unfortunately because of the FOREVER if theres no match then loop just pauses at that point forever, i figured a low number like 5 will help but it goes back to ignoring the regions image and continues with loop unless i add the FOREVER – Drake14 Feb 11 '16 at 16:23