← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #289066]: Variable values not carrying over to functions called from separate scripts

 

Question #289066 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/289066

Description changed to:
Edit: I've recreated the problem in 3 test scripts, which are much
simpler than my whole project. But if we can solve the issue in my test
files, I can apply the solution to the actual project. If you started
looking through the mountains of code I posted before, I'm sorry to have
wasted your time.

My scripts are as follows:

Test.sikuli:
import os,sys
from Test_Lib import *
from Test_Function import *
testvar1 = "TEST1"

print(testvar1)
print(testvar2)

printTest1()
printTest2()

Test_Lib.sikuli:
testvar2 = "TEST2"

Test_Function.sikuli:
def printTest1():
    print(testvar1)
def printTest2():
    print(testvar2)

Here's the problem:

When I execute Test.sikuli, I get the following output:
TEST1
[error] script [ Test ] stopped with error in line 7
[error] NameError ( name 'testvar2' is not defined )

Obviously, the variable testvar1 is getting through. But testvar2 is not
defined.

When I had all of these functions and variables stored in a single
script, it all worked flawlessly. But now that I've broken out the
functions of the script into their own modules, and called them from one
another, the variable values don't carry over from Test into the
printTest2() function it calls from Test_Function. How can I make it so
that when I set a variable value in the one script, that value carries
forward into all scripts and functions called henceforth? I played
around a bit with using the "global" keyword, but it doesn't seem to
help.  Please be gentle with me. I'm still a Python beginner. Where have
I gone wrong?

Additional info:
SikuliX Version: 1.1.0
Operating System: Windows 10
Java(TM) SE Runtime Environment: build 1.8.0_73-b02

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