I give Up. Docs make this seem simple enough, but just can't get it to work.

Asked by David

Hi
I have progressed in my skill that I want to start reusing functions by saving them and importing into other scripts.

I followed the docs. And that made it seem simple. But I keep getting [error] NameError ( global name 'click' is not defined)

So I followed another qquestion that said I would have to add the path to sys.path. I followed the provided example for theMain and theLib. That worked. So I added that to my script and still got the same error.

But I didn't really need to do that because the scripts are in the same folder.

So here are my scripts in the same folder:

TVTimeout.sikuli
----------------------------------------------------------
print "[Info1] This will only print once"

def Restart():
    print "[Info2] This will print everytime function is called"
    click(Pattern("1477780579267.png").similar(0.90).targetOffset(190,56))
    wait(2)
    if exists(Pattern("1477780687099.png").exact()):
        click(Pattern("1477780731704.png").exact().targetOffset(-49,0))
        wait(2)
    if exists("1477780864472.png"):
        click(getLastMatch())
        wait(1)
    if exists("1477780924740.png"):
        click(Pattern("1477780924740.png").exact().targetOffset(100,0))
        wait(1)
        click(Pattern("1477781026125.png").exact().targetOffset(148,0))
        wait(10)

TestTV.sikuli
-----------------------------
TVTimeout.Restart()

After restarting IDE and running TestTV.sikuli, I get this in the message window:
------------------------------------------------------------------------------------------------------------------------
[Info1] This will only print once
[Info2] This will print everytime function is called
[error] script [ TestTV ] stopped with error in line 3
[error] NameError ( global name 'click' is not defined )
[error] --- Traceback --- error source first line: module ( function ) statement 5: TVTimeout ( Restart ) click(Pattern("1477780579267.png").similar(0.90).targetOffset(190,56))
[error] --- Traceback --- end --------------

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1
Revision history for this message
David (davper) said :
#2

Hi
Yes, I followed that doc already. Is there something in my script that is not following of that?

Revision history for this message
masuo (masuo-ohara) said :
#3

It is written in the document as follows.
your imported script MUST contain (recommendation: as first line) the following statement:
from sikuli import *

[TVTimeout.sikuli]
from sikuli import * #<---
print "[Info1] This will only print once"

Revision history for this message
RaiMan (raimund-hocke) said :
#4

@masuo
thanks for your comment :-))

Can you help with this problem?

Provide an answer of your own, or ask David for more information if necessary.

To post a message you must log in.