Global variable access in Run Lua actions

If I’ve defined a global variable in UI7 using Startup Lua, as follows:

g_GlobalVar = {
   passStr="",
   passNum=0
}

…is it possible for me to use those values in Reactor? I’ve tried a number of rudimentary tests along those lines, but keep hitting errors like “Undefined” and “Unknown expression.” If it is possible, the syntax eludes me!

(In fact, I’ve never quite gotten the ‘Global Variable’ portion of the Reactor docs to work for me, so now I’m just very curious!)

  • Libra

No. Luup runs plugins in their own sandbox that is separate from the startup lua environment, and not derived from it.

Now I’m curious, too, because I’m not aware there is such a section. Can you link me to it?

Last 5 paragraphs of Expressions - Reactor

…in which case I may have naively taken “Exported Variable” to be synonymous with “Global Variables”.

(Considering the sandbox you describe, I now realize that’s impossible. Yet I don’t recall ever having success “seeing” nor “being able to reference” an “exported variable” inside a non-originating Reactor sensor, either.)

More homework for ol’ Libra. :wink:

UPDATE: Finally wrapped my head around it! I just needed to build (in the Expressions section of a non-originating Reactor sensor…) the following expression definition:

globalRVar := getstate( 180, "urn:toggledbits-com:serviceId:ReactorValues", "gTestVar" )

And voilà!!

Device State conditions also can be used in that way.

1 Like