ww2commander
Emperor
I keep getting a bad argument #1 to 'ipairs' (table expected, got nil) my code no matter what I try.
All I need to do is loop through the global table g_SeasonTurns and check if a turn is satisfied.
Can anyone tell me what I m doing wrong?
Heres the code with the bolded line being the problem:
And here is what my global table looks like (short extract):
All I need to do is loop through the global table g_SeasonTurns and check if a turn is satisfied.
Can anyone tell me what I m doing wrong?
Heres the code with the bolded line being the problem:
Code:
function CheckSeasonChange(playerID)
local player = Players[playerID]
local iturn = Game.GetGameTurn()
print("Entered CheckSeasonChange function triggered")
print("Turn:" .. iturn)
print("Active player is: " .. player:GetName())
[COLOR="Red"][B] for i, seasonData in ipairs (g_SeasonTurns) do[/B][/COLOR]
local iturnkey = seasonData.Turn
local seasontype = seasonData.Type
if iturnkey == iturn then
if seasontype == "Winter" then
print("winter has arrived")
elseif seasontype == "Spring" then
print("spring has arrived")
elseif seasontype == "Mud" then
print("Muddy season has arrived")
end
end
end
end
And here is what my global table looks like (short extract):
Code:
g_SeasonTurns = {
{Turn = 1, Type = "Winter"}, -- Test Value to be removed
{Turn = 2, Type = "Spring"}, -- Test Value to be removed
{Turn = 18, Type = "Mud"},
}