How to use global variables ??
Posted: Wednesday 14 June 2017 14:07
Hello, I'm developing a quite complex script with several global variables that I need to use every time when the event gets triggered. It's kind of reference counter that I want to use to make certain decisions in the script. For that reason I have instantiated and initiated the GLOBAL variables at the top of the script (TestVar = 0) and increase in the script. See example below:
TestVar = 0
commandArray = { }
If (TestVar == 0) then
[Do action 1...]
TestVar = TestVar + 1
else
DoFunction(TestVar)
end
return
This should work in C-code, HOWEVER I have the problem that TestVar is always initialized to 0 in every event trigger. And as a result, the else-statement with DoFunction(TestVar) is never reached. I found a workaround by using a User Variable, but this is not a very elegant solution as I have many of these variables, including some array's.
So, does anybody know how the value of global variables can be initialized once and then retained in each event trigger?
Many thanks!
TestVar = 0
commandArray = { }
If (TestVar == 0) then
[Do action 1...]
TestVar = TestVar + 1
else
DoFunction(TestVar)
end
return
This should work in C-code, HOWEVER I have the problem that TestVar is always initialized to 0 in every event trigger. And as a result, the else-statement with DoFunction(TestVar) is never reached. I found a workaround by using a User Variable, but this is not a very elegant solution as I have many of these variables, including some array's.
So, does anybody know how the value of global variables can be initialized once and then retained in each event trigger?
Many thanks!