Gadget and Widget Cross Communication
Moderator: Moderators
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Gadget and Widget Cross Communication
So.... Lets say I have a trigger/ condition that changes a local in one gadget. How can I get other gadgets and widgets to see this?
Re: Gadget and Widget Cross Communication
there is a tablething GG that all gadgets can read, you need to put your variable in it.
http://answers.springlobby.info/questio ... created-it
http://answers.springlobby.info/questio ... munication
probally good idea to use GG.dinobob.bla instead of just GG.bla to avoid conflicts with other widgets.
http://answers.springlobby.info/questio ... created-it
http://answers.springlobby.info/questio ... munication
probally good idea to use GG.dinobob.bla instead of just GG.bla to avoid conflicts with other widgets.
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
muhahahahahahahaha
YES!
YES!
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: Gadget and Widget Cross Communication
But you also want widgets to see it so GG won't work. You might want to instead use Spring.SetGameRulesParam(...) which can then be ready by widgets as well.
Re: Gadget and Widget Cross Communication
isnt there WG? (not sure)
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: Gadget and Widget Cross Communication
Yes there's WG, but that's only for widgets. Bob wants both to to communicate from gadget to gadget/widget.
a trigger/ condition that changes a local in one gadget. How can I get other gadgets and widgets to see this?
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
how do i do
??Spring.SetGameRulesParam(...)
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Gadget and Widget Cross Communication
This gadget and this widget have gadget -> widget communication.
The important bits*
Gadget synced (anywhere in synced)
Gadget unsynced
Widget:
*Lua may contain missing localisations and includes
The important bits*
Gadget synced (anywhere in synced)
Code: Select all
SendToUnsynced("MexEnergyEvent", teamID, allyTeamData.teams, energyWasted, ODenergy,summedMetalProduction,summedOverdriveMetal, teamEnergy[teamID].totalChange, teamIncome)
Code: Select all
function WrapToLuaUI(_,teamID, allies, energyWasted, energyForOverdrive, totalIncome, metalFromOverdrive, EnergyChange, teamIncome)
if (teamID ~= Spring.GetLocalTeamID()) then return end
if (Script.LuaUI('MexEnergyEvent')) then
Script.LuaUI.MexEnergyEvent(teamID, allies, energyWasted, energyForOverdrive, totalIncome, metalFromOverdrive, EnergyChange, teamIncome)
end
end
function gadget:Initialize()
gadgetHandler:AddSyncAction('MexEnergyEvent',WrapToLuaUI)
end
Code: Select all
function MexEnergyEvent(teamID, allies, energyWasted, energyForOverdrive, totalIncome, metalFromOverdrive, change, teamIncome)
if (Spring.GetLocalTeamID() == teamID) then
WG.energyWasted = energyWasted
WG.energyForOverdrive = energyForOverdrive
WG.change = change -- energy change by OD - substract that from income
WG.mexIncome = totalIncome-metalFromOverdrive
WG.metalFromOverdrive = metalFromOverdrive
WG.teamIncome = teamIncome
WG.allies = allies
end
end
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
okay
what am i doing wrong here
from gadget synced section
and widget:
what am i doing wrong here
from gadget synced section
Code: Select all
local function NextRound()
if curround < maxrounds then
curround = curround + 1
SendToUnsynced("RoundReset", curround)
DisplayScore()
echo( '-- Round ' .. curround .. " --" )
KillAll()
KillDead()
SpawnGear()
MakeAllWatchersBlind()
SpawnStarters()
else
--Game Over
gameover = true
KillLosingAlliances()
DisplayScore()
end
end
Code: Select all
function RoundReset(curround)
if ((curround ~= nil) and (curround > lastround)) then
lastround = curround
local x, y, z = Spring.GetTeamStartPosition(Spring.GetMyTeamID())
local unitArray = Spring.GetTeamUnits(Spring.GetMyTeamID())
if (unitArray and #unitArray==1) then
--Spring.SelectUnitArray(unitArray[1])
Spring.SelectUnitArray(unitArray)
x, y, z = Spring.GetUnitPosition(unitArray[1])
end
if x and y and z then
Spring.SetCameraTarget(x, y, z)
end
end
--end
end
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Gadget and Widget Cross Communication
By the look of it you didn't look at the central codeblock of my last post.
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
Lies! This doesn't work.. I'll get echos saying the lauUI script is found, but the local is always nil and never comes out of sync to unsync.
Gadget parts:
Widget:
Gadget parts:
Code: Select all
...
local function NextRound()
if curround < maxrounds then
curround = curround + 1
DisplayScore()
echo( '-- Round ' .. curround .. " --" )
SendToUnsynced("NewRoundNotice", curround)
KillAll()
KillDead()
SpawnGear()
MakeAllWatchersBlind()
SpawnStarters()
else
--Game Over
gameover = true
KillLosingAlliances()
DisplayScore()
end
end
......
----- SYNCED -----
-------------------------------------
else
-------------------------------------
----- UNSYNCED -----
function RoundNotifier(curround)
Spring.Echo("looking for luaUI w round", curround)
if (Script.LuaUI('NewRoundNotice')) then
Spring.Echo("Found luaUI")
Script.LuaUI.NewRoundNotice(curround)
end
end
function gadget:Initialize()
Spring.Echo("sent to unsync w round", curround)
gadgetHandler:AddSyncAction('NewRoundNotice',RoundNotifier)
end
Code: Select all
function widget:GetInfo()
return {
name = "Commander Zoom Mid Round",
desc = "Zooms to Commander after round restarts",
author = "quantum and Evil4Zerggin and zwzsg, modded by bobwithbeer",
date = "Jul 11, 2007",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
function widget:Initialize()
widgetHandler:RegisterGlobal("NewRoundNotice", NewRoundNotice)
local lastround = 0
if (CheckForSpec()) then return false end
end
function CheckForSpec()
if Spring.GetSpectatingState() or Spring.IsReplay() then
widgetHandler:RemoveWidget()
return true
end
end
function NewRoundNotice(curround)
Spring.Echo("Round called", curround)
if ((curround ~= nil) and (curround > lastround)) then
local x, y, z = Spring.GetTeamStartPosition(Spring.GetMyTeamID())
local unitArray = Spring.GetTeamUnits(Spring.GetMyTeamID())
if (unitArray and #unitArray==1) then
--Spring.SelectUnitArray(unitArray[1])
Spring.SelectUnitArray(unitArray)
x, y, z = Spring.GetUnitPosition(unitArray[1])
end
if x and y and z then
Spring.SetCameraTarget(x, y, z)
lastround = curround
end
end
end
function widget:GameFrame(f)
--- to double check
if f %30 < 1 then
NewRoundNotice(curround)
end
end
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Gadget and Widget Cross Communication
Idk, get the CA gadget and widget pair and delete things from both that look unimportant until it stops working.
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: Gadget and Widget Cross Communication
in widget: move Initialize() after your NewRoundNotice(). I remember there were problems with ordering of functions, e.g. could be nil if it is defined later.
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
Good idea, but it didn't help. Still only getting nil.
okay.. I'm getting this in the log for my echos in the gadget section.
[ 2497] looking for luaUI w round, NewRoundNotice <<--echo in gadget: "Spring.Echo("looking for luaUI w round", curround)"
[ 2497] Found luaUI <<--echo in gadget
[ 2497] Round called, NewRoundNotice <<--- echo in widget " Spring.Echo("Round called", curround)"
does this mean that the gadget is trying to send "NewRoundNotice" as a curround value?
?
okay.. I'm getting this in the log for my echos in the gadget section.
[ 2497] looking for luaUI w round, NewRoundNotice <<--echo in gadget: "Spring.Echo("looking for luaUI w round", curround)"
[ 2497] Found luaUI <<--echo in gadget
[ 2497] Round called, NewRoundNotice <<--- echo in widget " Spring.Echo("Round called", curround)"
does this mean that the gadget is trying to send "NewRoundNotice" as a curround value?
?
Re: Gadget and Widget Cross Communication
Why the heck didn't you posted the output right next to your widget???
Oh yeah it makes so much fun to search errors w/o getting any hints ...
NEXT time post ALWAYS the (including error) messages when you expect help!
SO your arguments declaration in the widget are wrong. Replace "NewRoundNotice(curround)" with "NewRoundNotice(...)"
and add a "Spring.Echo(...)" to get+see all arguments. Their values may indicate what you are searching for.
Oh yeah it makes so much fun to search errors w/o getting any hints ...
NEXT time post ALWAYS the (including error) messages when you expect help!
SO your arguments declaration in the widget are wrong. Replace "NewRoundNotice(curround)" with "NewRoundNotice(...)"
and add a "Spring.Echo(...)" to get+see all arguments. Their values may indicate what you are searching for.
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
[ 1710] Widget notice called
[ 1710] nil
[ 1729] SCORE: (Alliance 1: 1) (Alliance 0: 0)
[ 1729] -- Round 2 --
[ 1729] looking for luaUI w round, NewRoundNotice
[ 1729] Found luaUI
[ 1729] Widget notice called
[ 1729] NewRoundNotice <--- indicates this is all that is being recieved??
[ 1740] Widget notice called
[ 1740] nil
with widget changed top this:
[ 1710] nil
[ 1729] SCORE: (Alliance 1: 1) (Alliance 0: 0)
[ 1729] -- Round 2 --
[ 1729] looking for luaUI w round, NewRoundNotice
[ 1729] Found luaUI
[ 1729] Widget notice called
[ 1729] NewRoundNotice <--- indicates this is all that is being recieved??
[ 1740] Widget notice called
[ 1740] nil
with widget changed top this:
Code: Select all
function widget:GetInfo()
return {
name = "Commander Zoom Mid Round",
desc = "Zooms to Commander after round restarts",
author = "quantum and Evil4Zerggin and zwzsg, modded by bobwithbeer",
date = "Jul 11, 2007",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
function CheckForSpec()
if Spring.GetSpectatingState() or Spring.IsReplay() then
widgetHandler:RemoveWidget()
return true
end
end
function NewRoundNotice(...)
Spring.Echo("Widget notice called")
Spring.Echo(...)
if (curround ~= nil) then
if (curround > lastround) then
local x, y, z = Spring.GetTeamStartPosition(Spring.GetMyTeamID())
local unitArray = Spring.GetTeamUnits(Spring.GetMyTeamID())
if (unitArray and #unitArray==1) then
--Spring.SelectUnitArray(unitArray[1])
Spring.SelectUnitArray(unitArray)
x, y, z = Spring.GetUnitPosition(unitArray[1])
end
if x and y and z then
Spring.SetCameraTarget(x, y, z)
lastround = curround
end
end
end
end
function widget:GameFrame(f)
--- to double check
if f %30 < 1 then
NewRoundNotice(curround)
end
end
function widget:Initialize()
widgetHandler:RegisterGlobal("NewRoundNotice", NewRoundNotice)
local lastround = 0
if (CheckForSpec()) then return false end
end
Re: Gadget and Widget Cross Communication
k the error is earlier in the pipe
PS: it is even visible in the log
.
PPS: k, you even noticed that, just didn't knew how to handle such errors ^^
the arguments of RoundNotifier(curround) are wrong, add here the "..." to see all arguments and select the correct ones.bobthedinosaur wrote:Code: Select all
function RoundNotifier(curround) Spring.Echo("looking for luaUI w round", curround) if (Script.LuaUI('NewRoundNotice')) then Spring.Echo("Found luaUI") Script.LuaUI.NewRoundNotice(curround) end end function gadget:Initialize() Spring.Echo("sent to unsync w round", curround) gadgetHandler:AddSyncAction('NewRoundNotice',RoundNotifier) end
PS: it is even visible in the log
From the code you wanted to see a number there and not the function namebobthedinosaur wrote:[ 1729] -- Round 2 --
[ 1729] looking for luaUI w round, NewRoundNotice

PPS: k, you even noticed that, just didn't knew how to handle such errors ^^
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
okay. I now know what was wrong. if you notice my code in the unsync portion of the gadget i do not include a _, at the begging of the function and so it was sending the function name instead of the value...
thanks for every ones help and patience!
thanks for every ones help and patience!
- bobthedinosaur
- Blood & Steel Developer
- Posts: 2702
- Joined: 25 Aug 2004, 13:31
Re: Gadget and Widget Cross Communication
Something that was never really discussed earlier in this old thread. Widget to gadget communication, how would one set that up?
Say I wanted to send the user's playerID along with some other data to a gadget.
Say I wanted to send the user's playerID along with some other data to a gadget.