Lua script variables


I am new to Lua scripting for the Exosite portal and the Lua language.

Is there a way I can declare a variable in a portal script so that it is accessible from other device scripts and other portal scripts? Anything I have tried just results in a “global namespace is reserved” error message. I would also like to be able to display a script variable value in a big number widget on a dashboard. I am not interested in the variable history so don’t need to waste a device dataport. I am also interested in using the portal timer but I don’t know how it works. timer.value always seems to ==1 and timer.wait() seems to wait forever. Any code examples or references to documentation that explains these things would be much appreciated.

Thanks Keith


Hi Keith,

I´ve also tried to created global variables, but the way I figured out how to do it, without holding data is configuring a dataport not to keep the records and use it as my global variable.

We also used a static dataport as timer - calling it by it´s alias. ie:

local timer = alias['fixed_timer']
local ts1 = fixed_timer.wait(now+600) -- Will wait for 10 minutes

Hope this helps.


Thanks for your help. I came to a similar conclusion as a way to do what I wanted. I am still puzzled about how to use the Portal script timer for any thing. It appears as a data source choice for dashboard widgets.