It’s in a script module. Doesn’t the script module load again each time I call a function from a script? For example if I had two buttons calling buttonA and buttonB wouldn’t I get 5 twice? Or would I get an error since x isn’t defined in buttonB().
x = system.tag.read('[client]HMI/x').value ## THIS EQUALS 5
def buttonA():
y = x
if y == 0:
return 0
else:
return y
def buttonB():
y = x
if y == 0:
return 0
else:
return y
No. That's the point of a script module--loads once. Running the "def" statement creates the function as a named object, nicely not-quite-compiled, so it runs fast when you call it.
The difference with Ignition is I never have to import anything to run the script. So my final question then is if I have a script module with 100 functions at what point will the script module be compiled and brought into memory? The first time I call a function?