Occasionally I have a very real need to pass information form synced to unsynced or even just from widget to widget or gadget to gadget. The problem is that all of the infor I have found on the wiki for this is rather vague.
I understand that you use gadget/widget globals for this I.E. GG or WG, but how are these declared?
Is it simply GG.myVarName and suddenly widgets can pull the data from it? Does it require some sort of a go-between?
ELI5 plox
Explicit Instructions for using GG or WG
Moderator: Moderators
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Explicit Instructions for using GG or WG
GG - gadget globals
WG - widget globals
These tables are used for sharing data between addons in the same Lua interface. You cannot share between widget<->gadget nor synced_gadget <-> unsynced_gadget.
This is the relevant wiki page (https://springrts.com/wiki/LuaTutorials ... unications) - and it might need extending.
WG - widget globals
These tables are used for sharing data between addons in the same Lua interface. You cannot share between widget<->gadget nor synced_gadget <-> unsynced_gadget.
This is the relevant wiki page (https://springrts.com/wiki/LuaTutorials ... unications) - and it might need extending.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Explicit Instructions for using GG or WG
So if I have synced data that I need to sent to send to unsynced, so for this example lets say gadget -> widget, then I would use RulesParams.
This doesn't help me though, not really anyway. If I have a variable set in synced gadgetspace, how do I make it so that a widget can read that variable data? Is it completely impossible? Keep in mind, I'm talking about reading from unsynced only, not writing.
This doesn't help me though, not really anyway. If I have a variable set in synced gadgetspace, how do I make it so that a widget can read that variable data? Is it completely impossible? Keep in mind, I'm talking about reading from unsynced only, not writing.
Re: Explicit Instructions for using GG or WG
The alternative way of communicating is to use SendToUnsynced and then Script.LuaUI, but there's no guarantee of persistancy, as LuaUI might be reloaded afterwards.Forboding Angel wrote:So if I have synced data that I need to sent to send to unsynced, so for this example lets say gadget -> widget, then I would use RulesParams.
This is how you do it. In the gadget you set the gamerules param, which you should update each time your value changes.Forboding Angel wrote:If I have a variable set in synced gadgetspace, how do I make it so that a widget can read that variable data? Is it completely impossible? Keep in mind, I'm talking about reading from unsynced only, not writing.
Code: Select all
Spring.SetGameRulesParam("myVariable", myValue)
Code: Select all
local myVariable = Spring.GetGameRulesParam("myVariable")
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Explicit Instructions for using GG or WG
Aha! The lightbulb shows a glimmer.
In the particular usage I need right now it would be update every 30 frames or so. I'll give it a whirl and see what I come up with
Also, you never really answered how to use GG and WG. Do you just do GG.myVariableName? In another gadget/widget, how do you use it?
If I set something like GG.myVariableName = 5 in one gadget, can I then go to another gadget and say myCalc = GG.myVariableName + 5 and then myCalc = 10?
In the particular usage I need right now it would be update every 30 frames or so. I'll give it a whirl and see what I come up with
Also, you never really answered how to use GG and WG. Do you just do GG.myVariableName? In another gadget/widget, how do you use it?
If I set something like GG.myVariableName = 5 in one gadget, can I then go to another gadget and say myCalc = GG.myVariableName + 5 and then myCalc = 10?
Re: Explicit Instructions for using GG or WG
Correct. That will work as long as your assumption about the order of execution holds (it'll depend on the layer of the addon as well as what call you're invoking it in). Normally you'll just check if GG.myVariableName ~= nil before doing this calculation.Forboding Angel wrote:If I set something like GG.myVariableName = 5 in one gadget, can I then go to another gadget and say myCalc = GG.myVariableName + 5 and then myCalc = 10?
The best way to think of GG and WG is just as globally accessible tables.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Explicit Instructions for using GG or WG
They even are globally accessible tables, within their respective lua states.The best way to think of GG and WG is just as globally accessible tables.
RulesParams, SendToUnsycned, etc have more complicated implementations - the engine interacts there. I fully agree that lua comms page needs a rewrite, imo its by far the worst part of the lua docs. Had been meaning to do it one day.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Explicit Instructions for using GG or WG
Very cool, thank you. Set and Get GameRulesParam is a really simple way of shifting data around, that is extremely helpful. I've tried to figure this out before, but frankly, the wiki docs on it made no sense to me whatsoever.
Honestly, Gajop's post on GameRulesParam should just be c&p to that section, barring better documentation.
Honestly, Gajop's post on GameRulesParam should just be c&p to that section, barring better documentation.