extern variables?

extern variables?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
vebyast
Posts: 5
Joined: 03 Nov 2010, 07:05

extern variables?

Post by vebyast »

I'm attempting to write a widget for profiling and controlling your metal maker economy. Basically, it would let you quickly select your hover target, it would let you force on or force off all of your makers at once, and it would tell you roughly how much energy and metal your metal makers are dealing with. Later on I might build my own backend and start adding features (for example, taking allies' energy donations into account, or giving your excess energy to stalled allies rather than feeding it into inefficient metal makers).

For now, though, my intended implementation involves hooking into TheFatController's Improved MetalMakers widget. It sounds like it should be possible to get to its global control variables from my own widget, but I'm having trouble doing so. The variables in question are defined like this, in unit_improved_metal_maker.lua:

Code: Select all

-- global vars (so other widget (i.e. guis) can interact with the widget)
mmw_update         = 1.25  -- Seconds per update, do not set this too low
mmw_etargetPercent = 0.5   -- Percent of energy bar to aim for
mmw_estallPercent  = 0.3   -- Percent of "mmw_etargetPercent", when energy stalling begins (30% of 50% -> 15%)
mmw_forceStall     = false
I've tried a few things, mostly variations on the following (as well as a few wild attempts that I came across in the forums or in other widgets, all of which turned out to only work on things defined in luarules):

Code: Select all

local temp = mmw_update
local temp = _G.mmw_update
local temp = _G["mmw_update"]
Everything I do either results in temp == nil or a null pointer exception on _G. I've never done any Lua development, so I feel like I'm missing something really, really obvious. Any tips?
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: extern variables?

Post by Niobium »

There is a global table named 'WG' that you can access from all widgets.

i.e.
Widget A: "WG.SomeName = 3"
Widget B: "Spring.Echo(WG.SomeName)"

Easy as that.
User avatar
vebyast
Posts: 5
Joined: 03 Nov 2010, 07:05

Re: extern variables?

Post by vebyast »

Hah. Suddenly everything makes sense. WG for "Widget Global".

I already have gl figured out, so I think I'll be ready to put up a project thread by the end of the week. Thanks for the help.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: extern variables?

Post by knorke »

i think in a similiar way there is also GG for gadgets.
Post Reply

Return to “Lua Scripts”