Page 1 of 1

Global variable

Posted: 18 Dec 2020, 20:57
by daryl
Hello,
Please can you help me with a global variable? :
I need to send a variable from gadget to widget but some error appear during tests:

code in gadget:

Code: Select all

----
--sync
----
function gadget:GameFrame(n)
[...]
SendToUnsynced("start",1,0)
end
[...]
----
--unsync
----
function gadget:Initialize()
  gadgetHandler:AddSyncAction("start", Start) 
end

local function Start(vala,valb)
[...]
code in widget:

Code: Select all

local function test(vala,valb)
  if (vala == 1) then
        Spring.Echo("test ok") 
         end
end

function widget:Initialize()
	widgetHandler:RegisterGlobal('start',test)
end
what is wrong??

Re: Global variable

Posted: 18 Dec 2020, 22:01
by ivand
Have a look here for the concept: viewtopic.php?p=462489#p462489 or check any modern game sources to get working example.

Re: Global variable

Posted: 19 Dec 2020, 13:21
by daryl
Hi Ivand.. the link was helpful!!! Thank you!!!