Receiving error when run code through function

Asked by David on 2018-10-09

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.

Question information

Language:
English Edit question
Status:
Expired
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-10-10
Last reply:
2018-10-26
RaiMan (raimund-hocke) said : #1

the error messages do not fit to the pasted code:
--- click("1539113672446.png") is not in Accept
--- 1532724815166.png is not in the main script

David (davper) said : #2

I know, That is part of my problem. The error that keeps coming up doesn't appear to relate to my script but it references the correct script.

Launchpad Janitor (janitor) said : #3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.