Page 1 of 1

Widgets communicating with each other?

Posted: 25 Aug 2009, 01:32
by Caydr
Sorry for the nub question, I am a nub, ha ha, oh dear, what ever will I do with myself.

Now that that's over with, I'm wondering if it's possible for one widget to communicate with another widget. For instance, make a widget enable/disable another widget or change another widget's parameters.

Re: Widgets communicating with each other?

Posted: 25 Aug 2009, 01:38
by zwzsg
Yes.

The easy way is to have them share a variable in WG, like one widget do WG.CaydrStuff=x, and another can read WG.CaydrStuff and even re-write it.

The recommended way is to use:
http://springrts.com/wiki/Lua_UnsyncedC ... LuaMessage
and

Re: Widgets communicating with each other?

Posted: 25 Aug 2009, 01:44
by Caydr
Interesting. What's this mean: (needs ModUICtrl)

I am nub at writing original lua but hardcore pro at hacking pre-existing lua... are there any widgets you can point me to that use this method of communication?

Re: Widgets communicating with each other?

Posted: 25 Aug 2009, 02:05
by zwzsg
Caydr wrote:Interesting. What's this mean: (needs ModUICtrl)
It means that if someone is both pro enough and stupid enough to manually edit his springsettings.cfg to have LuaModUICtrl=0 then tons of gadgets and widgets will break.

Re: Widgets communicating with each other?

Posted: 25 Aug 2009, 02:10
by Regret
Caydr wrote:I am nub at writing original lua but hardcore pro at hacking pre-existing lua... are there any widgets you can point me to that use this method of communication?
RedUI uses it to create a table of functions for other widgets to include.

Just imagine WG as a table that can be accessed from every widget (after initialize).

Re: Widgets communicating with each other?

Posted: 25 Aug 2009, 02:21
by zwzsg
Kernel Panic 3.6, use WG for communication between kp_midknight_bg.lua and kp_tooltip.lua (and also kp_onshelp.lua).

You can also see an exemple of communcation by SendMessage between synced gadget <-> unsynced gadget <-> widget in \LuaRules\Gadgets\spawn_units.lua and \LuaUI\Widgets\dump_units.lua

Re: Widgets communicating with each other?

Posted: 25 Aug 2009, 02:54
by lurker
To be clear, you only use messages if you want to send it to other computers. Otherwise WG (though disabling a widget doesn't take any communication at all). You can also talk between widgets and unsynced gadgets with a helper function.