Gadget Unsynced functions

Gadget Unsynced functions

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

Moderator: Moderators

Post Reply
super_g
Posts: 13
Joined: 12 Jan 2012, 04:10

Gadget Unsynced functions

Post by super_g »

my gadget unsyced code does not seem to run at all. I have tried many different functions in the unsynced portion, such as:

function gadget:Update()
function gadget:Initialize()

I can not even get the below posted example to run the unsynced portion.

if (gadgetHandler:IsSyncedCode()) then
--SYNCED CODE
local number = 10 -- declaring local variable 'number'
function gadget:SomeSyncedCallin(...)
number=number+1 -- increment variable's value by one
_G.number=number -- save the new value into a global variable
end
else
--UNSYNCED CODE
function gadget:SomeUnsyncedCallin(...)
Spring.Echo(SYNCED.number) -- print the global variable's value on screen
end
end

Is there a special way to register the unsynced functions?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Gadget Unsynced functions

Post by FLOZi »

Does your game have a LuaRules/draw.lua which includes the gadgethandler?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Gadget Unsynced functions

Post by knorke »

super_g wrote: --UNSYNCED CODE
function gadget:SomeUnsyncedCallin(...)
Some callins do not get called in unsynced.
eg function gadget:GameFrame (f)

http://answers.springlobby.info/questio ... d-luarules

http://answers.springlobby.info/questio ... ced-gadget
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Gadget Unsynced functions

Post by FLOZi »

Update and Initialize are certainly called in unsynced; I suspect this is the issue:

http://answers.springlobby.info/questio ... nitialized
Nerris
Posts: 6
Joined: 10 Feb 2012, 23:20

Re: Gadget Unsynced functions

Post by Nerris »

THANK YOU!

I'm currently working with Super_G on this project, and this solved the issue beautifully. We were missing draw.lua
Post Reply

Return to “Lua Scripts”