← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #189351]: Pass Return as Argument

 

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

RaiMan posted a new comment:
Yes that works of course, but that is not really the solution.

The return value of a function is its value and can be used as every
other variable:

--1: use additional var:

text = displayText()
displayTextTwo(text)

--2: use it directly:

displayTextTwo(displayText())

comment on --1.
The variable text in this case exists 2 times:
-- in the scope of displayText() (only known and useable in the function)
-- in the scope of the script (text is global in this case and can be read in every function, that does not have its own var text (which will be used in the function in this case))

Since giving a value to a variable is usually done by " var=value ", which defines the variable too if it does not exist yet, it is known only in the scope, where it is defined (text in displayText() in your case, so it is not known in displayText2 - So finally  " global var " did what you want).
So if you want to assign a value to a global variable inside a function, you have to tell Python " global var " before using " var = value ".

One more thing:
If you really need global variables (as you have seen, not in your case), you can use Sikuli's class Settings for that:

# in main workflow
Settings.some_var = value

# in a def() or any imported module
localVar = Settings.some_var

But have a look before about the variables Sikuli already uses with Settings class, so you do not overwrite them.
The safest way is to name the variables like
Settings.mySomeVar

since the prefix my... is not used in the Settings class by Sikuli.

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.