Silly simple question... PlayerDoTurn

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
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.

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.
 
if g_lastTurn < gameTurn then

Only for Player #0 will this be true, because you are updating the data in g_lastTurn as the 1st command after the conditional "if" line. So only for player #0 is anything getting processed past the conditional line
 
Back
Top Bottom