I have some coloring I am doing to the ui and a few other common values that I store in a config... problem is for each widget to use them I would need to put it in widget global(wg) so how can I ensure that it the var is in wg before the widget loads? as in how do I set the load precedence?
Also is this a good way to do it or would one of you recommend a different approach?
I have multiple widgets using the same variables..
Moderator: Moderators
Re: I have multiple widgets using the same variables..
this, and maybe make the WG-loading widget an unsynced gadget so it can not be accidently disabled. (if unsynced gadget can write to WG but I think yes)The simplest approach is to set the layer of the widget that sets up the WG variables to something extremely low, so that it initialized before the other widgets.
(or check in the other widgets if WG.bla ~= nil)
Re: I have multiple widgets using the same variables..
Code: Select all
if gadgetHandler:IsSyncedCode() then
--SYNCED
function gadget:Initialize()
BuildColorSets()
GG.colors = colorSets
_G.colors = colorSets
end
else
--UNSYNCED
function gadget:Initialize()
WG.colors = SYNCED.colors
end
end
resultattempt to index global 'WG' (a nil value)
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: I have multiple widgets using the same variables..
Use Script.LuaUI to send data to widgets.smoth wrote:resultattempt to index global 'WG' (a nil value)
Afaik you cannot access WG from gadgets. Even if you could, widgets are loaded after gadgets. So it wouldn't work in gadget:Initialize.
Re: I have multiple widgets using the same variables..
hm too bad, was not sure.
Guess then every widget should have something like
if not WG.myWidgetSettingStuff then ... end
in case the framework widget is disabled/failed.
I think in early CA some chili widgets did not have that and so clicking around in F11 could cause error spam.
btw what happend to Niobiums post? (the one i quoted)
Guess then every widget should have something like
if not WG.myWidgetSettingStuff then ... end
in case the framework widget is disabled/failed.
I think in early CA some chili widgets did not have that and so clicking around in F11 could cause error spam.
btw what happend to Niobiums post? (the one i quoted)
Re: I have multiple widgets using the same variables..
Maybe he deleted it? I figured you were quoting yourself.
I'll just have to make the widget load either as a widget or pass it peacemeal via Script.luaui lik chickens does but I would have to do it for each widget :/.
Kinda lame
I'll just have to make the widget load either as a widget or pass it peacemeal via Script.luaui lik chickens does but I would have to do it for each widget :/.
Kinda lame
Re: I have multiple widgets using the same variables..
Yeah the post was mine, I deleted it to do some actual testing of what I said, then when I came back to repost it knorke had quoted it, so that was good enough.
In regards to the widget problem, ideally users wouldn't be going into the widget list and disabling essential widgets, but there is another way: load the config outside of a callin.
When the widget handler loads this widget from file (Which it always does - As it has no information about it otherwise) it executes the script, which sets up the WG variable. After loading the widget the handler has access to its name/callins/enabled state etc and may choose to disable it, but the variables have already been set.
In regards to the widget problem, ideally users wouldn't be going into the widget list and disabling essential widgets, but there is another way: load the config outside of a callin.
Code: Select all
function widget:GetInfo()
...
end
WG.Config = {cat = 'meow'}