Gadget and Widget Cross Communication
Posted: 13 Dec 2010, 17:23
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?
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
a trigger/ condition that changes a local in one gadget. How can I get other gadgets and widgets to see this?
??Spring.SetGameRulesParam(...)
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
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
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
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
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
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