OuroborosOrder
Warlord
Say I am trying to do something like:
Would the global LUA tables created in this script persist between turns/calls to the script in game? I was thinking this might be a good way to reduce overhead.
Code:
-- UnitTracker.Lua
-- Created By Ouroboros
-- 4/8/2016
g_pUnitData = {}
g_pUnitTurnLog = {};
function SetClassesToTrack()
for pUnit in GameInfo.Units() do
if pUnit.Class == "UNITCLASS_SWORDSMAN" or pUnit.Class == "UNITCLASS_SPEARMAN" or pUnit.Class == "UNITCLASS_WARRIOR" then
-- Will this persist across calls to this script each turn?
table.insert(g_pUnitData, {pUnit.ID = {pUnit.Type, pUnit.Class});
end
end
end
function TrackUnits(iPlayer)
local iTurn = Game.GetGameTurn();
local pPlayer = Players[iPlayer];
if iTurn == 0 then
SetClassesToTrack();
end
for pUnitData in g_pUnitData do
if pPlayer.HasUnitOfClassType(iUnitID.Class) then
table.insert(iTurn, pUnitData);
end
end
print("Unit Class Tracker:");
print(g_pUnitTurnLog);
-- We could do other things with this type of data, including creating an in game unit-turn tracking log for the player.
end
-- Register the function with the do turn event which is run on each player turn.
GameEvents.PlayerDoTurn.Add(TrackUnits);
Would the global LUA tables created in this script persist between turns/calls to the script in game? I was thinking this might be a good way to reduce overhead.