Global Variables
Global variables that survive across script executions
This example shows how to use a global that is shared across script executions. Although top scoped variables will save across script executions most times, this global is guaranteed to exist whereas a top scoped variable is not if the LuaScript environment is reset (this however survives resets if they occur).
-- First, we have to check if the variable is null or not, and if it
-- is we will initialize it to the value/type we want.
if global.counter == nil then
-- Init as an numeric
global.counter = 0
ui.Log("Counter initialized to " .. global.counter)
else
-- The value was already init'd, let's increment it.
global.counter = global.counter + 1
end
-- Show the new value of the global
ui.Log("Counter now at " .. global.counter)