Craig_Sutter
Deity
Why is this code only printing for one player... Player 0. I am running my game on Autoplay if that matters.
Anyhow, until recently, functions that I have run within the below PlayerDoTurn function have been using a loop to go through the players. Lately, though, I have come under the impression (mistakenly?) that PlayerDoTurn runs through each of the players in turn... therefore, to my mind, making a loop through the players redundant. So I got rid of all my player loops in the functions run within PlayerDoTurn. However, now I've noticed that they don't seem to be running on anybody's turn except for Player 0. This was truly brought to my attention by the function I put in place to do real time tracking of faith and gold to see why some purchases directed by other functions were not firing when they ought to have.
So, only one player is giving me the print out.
Should I be defining pPlayer = iPlayer within the PlayerDoTurn function instead of the subsidiary functions, and passing that along rather than using iPlayer? Or am I totally out to lunch on how the event actually works... and I do need to loop through the players in either the PlayerDoTurn function or the subsidiary functions?
Thank-you for answering what is probably a very straight forward and simple procedure for most of you.
Anyhow, until recently, functions that I have run within the below PlayerDoTurn function have been using a loop to go through the players. Lately, though, I have come under the impression (mistakenly?) that PlayerDoTurn runs through each of the players in turn... therefore, to my mind, making a loop through the players redundant. So I got rid of all my player loops in the functions run within PlayerDoTurn. However, now I've noticed that they don't seem to be running on anybody's turn except for Player 0. This was truly brought to my attention by the function I put in place to do real time tracking of faith and gold to see why some purchases directed by other functions were not firing when they ought to have.
So, only one player is giving me the print out.
Code:
--to set up turn by turn tracking if needed
local g_lastTurn = -1
local function OnPlayerDoTurn(iPlayer)
local pPlayer = Players[iPlayer]
--print("OnPlayerDoTurn ", pPlayer:GetName())
local gameTurn = Game.GetGameTurn()
if g_lastTurn < gameTurn then
g_lastTurn = gameTurn
--per game turn function here
print("Turn...", gameTurn)
faithgoldcalc(iPlayer)
end
end
GameEvents.PlayerDoTurn.Add(OnPlayerDoTurn)
function faithgoldcalc(iPlayer)
local pPlayer = Players[iPlayer]
if (pPlayer:IsAlive ()) and not pPlayer:IsMinorCiv() and not pPlayer:IsBarbarian() then
currentGold = pPlayer:GetGold()
currentFaith = pPlayer:GetFaith()
print(pPlayer:GetName() ,">>>>>>>>> Gold...", currentGold, "and Faith...", currentFaith)
end
end
Should I be defining pPlayer = iPlayer within the PlayerDoTurn function instead of the subsidiary functions, and passing that along rather than using iPlayer? Or am I totally out to lunch on how the event actually works... and I do need to loop through the players in either the PlayerDoTurn function or the subsidiary functions?
Thank-you for answering what is probably a very straight forward and simple procedure for most of you.