How to use global variables

Modified on Mon, 6 Sep, 2021 at 10:30 AM

Inside function node's code the general lua rules apply: https://www.lua.org/pil/4.2.html


In LuvitRED there is an additional way to use global or flow wide variables. Using this method a variable can be accessed from within every function node.


By using the prefix global, the variable will be stored in RAM with the key following the prefix (separated by a . ). This method is identical to using the 'global store' node to store a variable to RAM, and both can be used together. 


example:

function block 1
global.variable = msg.payload
return


function block 2
if global.variable ~= nil then
    msg.payload = global.variable
return msg


The attached flow demonstrates the use of the multiple ways to store/retrieve variables in LuvitRED.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article