Widgets communicating with each other?

Widgets communicating with each other?

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

Moderator: Moderators

Post Reply
User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Widgets communicating with each other?

Post 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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Widgets communicating with each other?

Post 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
User avatar
Caydr
Omnidouche
Posts: 7179
Joined: 16 Oct 2004, 19:40

Re: Widgets communicating with each other?

Post 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?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Widgets communicating with each other?

Post 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.
Regret
Posts: 2086
Joined: 18 Aug 2007, 19:04

Re: Widgets communicating with each other?

Post 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).
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Widgets communicating with each other?

Post 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
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Widgets communicating with each other?

Post 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.
Post Reply

Return to “Lua Scripts”