← Back to team overview

sikuli-driver team mailing list archive

[Question #674936]: Receiving error when run code through function

 

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

Hi
I have a lib file with 2 functions. When I run them outside of a function, they work fine. But as a function one is constantly failing while the other works fine.

Here is my code
#contents of flexlib
from sikuli import *

Settings.MoveMouseDelay = 0
Settings.DelayBeforeMouseDown = 0
Settings.DelayBeforeMouseUp = 0


def Decline():
    click("1539113613250.png")
    click("1539113644689.png")
    wait("1539113672446.png",30)
    click("1539113672446.png")
    wait("1539113722667.png",30)
    click("1539113722667.png")

def Accept():
    moveMouse(Pattern("1539113847566.png").targetOffset(42,0))
    mouseDown(Button.LEFT)
    moveMouse(Pattern("1539113940648.png").targetOffset(-57,-3))
    mouseUp(Button.LEFT)
    click("1539113998877.png")
    


#Contents of wholefoods
import flexLib

Settings.MoveMouseDelay = 0
Settings.DelayBeforeMouseDown = 0
Settings.DelayBeforeMouseUp = 0
Phone = find(Pattern("1532767070365.png").similar(0.69))
setROI(Phone)
setAutoWaitTimeout(0)
Phone.setAutoWaitTimeout(0)

    


while True:
    if Phone.exists(Pattern("1532873575385.png").similar(0.95)):
        click(Pattern("1532873575385.png").similar(0.95))
        flexLib.Accept()
    elif Phone.exists(Pattern("1536865272142.png").similar(0.95)):
        click(Pattern("1536865272142.png").similar(0.95))
        flexLib.Accept()
    elif Phone.exists("1539112486644.png"):
        click("1539112486644.png")
        flexLib.Accept()
    
    elif Phone.exists("1532724477876.png"):
        try:
            Phone.hover("1532724477876.png")
            Phone.wait("1532724530555.png",60*60)
            
            Phone.click("1532724530555.png")
        except:
            pass
        wait(.4)
    else: 
        flexLib.Decline()
    

The code inside flexLib.Accept() runs fine if I run it stand alone outside of a function. But inside the function when called, is giving me this error:

[log] CLICK on L(1104,453)@S(0)[0,0 1920x1080]

[error] Image: could not be loaded: file:///DAVID-PC/Users/David/Documents/Sikuli/scripts/Wholefoods.sikuli/1532724815166.png
[error] Image: Image not valid, but TextSearch is switched off!
[error] script [ Wholefoods ] stopped with error in line 24
[error] FindFailed ( Region: doFind: Image not loadable: 1532724815166.png )
[error] --- Traceback --- error source first line: module ( function ) statement 13: flexLib ( Accept ) click("1539113672446.png")
[error] --- Traceback --- end --------------

I have tried deleting the scripts and rebuilding with new screen captures thinking the images got corrupted. Didn't change anything.


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