The trouble you are experiencing is due to the fact that runScript() is prefixing the string you feed it with an assignment statement to a hidden variable. So the code that actually executes in Paul’s first suggestion looks like this:
And then the __someVar value is fished out of the local variable table to feed to the binding. Not valid python.
If you add a real newline to your string expression, you can print dir() to see what that variable name is. You can also assign a constant temporarily, with a newline, import, execute anything, and assign a real return value several lines later.
Do you know what is going on with my project? I am following the instructions PGriffith posted in Oct. 2018 but for some reason I am still getting an "Error_ExpressionEval"
Is your Test script in the global scripting project?
In v7.9, back when this post was made, the shared.* namespace was the only collection of scripts that could be used by tags.
In v8+, that was replaced by the global scripting project setting, allowing more flexibility through the project inheritance system. But other projects, like v7.9's project.* namespace, are not callable from tags.
First, you must create a script/function in your defined gateway scripting project - this is key!
For example, I created this function inside of the script shared.util.calc:
def getRandom(lower = 0, upper = 100):
'''
Returns a random integer between lower and upper ranges.
Args:
lower (int): Lower limit for random number
upper (int): Upper limit for random number
Returns:
int: Random integer between lower and upper limits
'''
import random
return random.randint(lower, upper)
Then my integer expression tag with an exectution mode set to fixed rate of 1000ms and the expression set to:
This is a v7.9 topic. In the future, make sure you post in an appropriate topic, or start a new topic. I (and others, I expect) did not mention the global scripting project because it isn't applicable to v7.9.
You mentioned it, but I saw other posts before I saw that "update for 8.1" comment.