Page 1 of 1

Can't read global variable in gadget

Posted: 06 Jun 2011, 22:38
by Pithikos
In one gadget I have in the synced part of the gadget a unit to be spawned in the following manner:

Code: Select all

_G.dummyID=Spring.CreateUnit("dummy_land", x, y, z, "south", gaiaTeamID);
Then in a second gadget I try to read the global(in the unsynced part) but I get nil:

Code: Select all

Spring.Echo("dummy has ID: ", _G.dummyID);
If I test this with a string it works perfectly but with the dummyID it doesn't. Why is that?

Re: Can't read global variable in gadget

Posted: 06 Jun 2011, 23:19
by jK
you may have seen GG.foobar already in other gadgets

Re: Can't read global variable in gadget

Posted: 07 Jun 2011, 00:03
by Pithikos
Nope. Last time I was checking some gadgets was some months ago and everyone used _G. Anyway I renamed all my _G.foobar to GG.foobar but same thing happens. Not sure where to get an example from..

Re: Can't read global variable in gadget

Posted: 07 Jun 2011, 01:59
by jK
k didn't saw this
Pithikos wrote:...in the synced part of the gadget
...in the unsynced part...
-> you did a logic error. how lua synced/unsynced works is explained on http://answers.springlobby.info/questions/

Re: Can't read global variable in gadget

Posted: 07 Jun 2011, 02:47
by Pithikos
jK wrote:k didn't saw this
Pithikos wrote:...in the synced part of the gadget
...in the unsynced part...
-> you did a logic error. how lua synced/unsynced works is explained on http://answers.springlobby.info/questions/
Did a search there too for "globals synced", "globals unsynced", "synced unsynced" but got 0 results.

I solved my problem anyway. I use SetGameRulesParam() though there is null documentation in the wiki about it(at least from what I searched). I wanted to encapsulate a table with this but it seems that the function only accepts variables.

Re: Can't read global variable in gadget

Posted: 07 Jun 2011, 03:08
by jK
Pithikos wrote:I use SetGameRulesParam() though there is null documentation in the wiki about it(at least from what I searched).
again wrong

Re: Can't read global variable in gadget

Posted: 07 Jun 2011, 03:53
by abma

Re: Can't read global variable in gadget

Posted: 07 Jun 2011, 08:44
by FLOZi
jK wrote:
Pithikos wrote:I use SetGameRulesParam() though there is null documentation in the wiki about it(at least from what I searched).
again wrong
http://springrts.com/wiki/Lua_System#Synced_2

Re: Can't read global variable in gadget

Posted: 07 Jun 2011, 11:30
by Pithikos
FLOZi wrote:
jK wrote:
Pithikos wrote:I use SetGameRulesParam() though there is null documentation in the wiki about it(at least from what I searched).
again wrong
http://springrts.com/wiki/Lua_System#Synced_2
Well seems to me that the function is in the wrong place. The Spring.GetGameRulesParam is in SyncedRead so I would expect Spring.SetGameRulesParam to be in SyncedCtrl. No idea what this "System Lua" is supposed to represent. A few words would not hurt whoever did it. :|