Can't read global variable in gadget

Can't read global variable in gadget

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Can't read global variable in gadget

Post 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?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Can't read global variable in gadget

Post by jK »

you may have seen GG.foobar already in other gadgets
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Can't read global variable in gadget

Post 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..
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Can't read global variable in gadget

Post 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/
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Can't read global variable in gadget

Post 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.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Can't read global variable in gadget

Post 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
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: Can't read global variable in gadget

Post by abma »

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Can't read global variable in gadget

Post 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
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: Can't read global variable in gadget

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

Return to “Game Development”