Logic Machine Forum
What about global and static variables - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: What about global and static variables (/showthread.php?tid=24)



What about global and static variables - Tinysprings - 07.07.2015

Hello,

I just started a few days ago to make some scripts and learn Lua.
I wonder about Lua global variables that were supposed to be shared between scripts and the unavailable static variables for subsequent or recursive calls.
The only way I have found is thru the 'storage' function. Am I missing something ? Huh

Thanx
Tiny


RE: What about global and static variables - admin - 08.07.2015

Yes, storage is one of possible approaches for global/static variables. In more advanced cases you can use an external Redis key-value database. This way several LMs can share data between them.

Only resident script variables are static by default. Simplified resident script logic:

Code:
while SCRIPT_ACTIVE do
  RUN_RESIDENT_FUNCTION()
  sleep(SCRIPT_SLEEP_TIME)
end



RE: What about global and static variables - Tinysprings - 08.07.2015

Thank you, that's clear.
I only tried with event fired scripts.

Tiny