"v" is by general convention used to refer to a "value" in a "key, value" pair stored within an lua table. Firaxis quite commonly pulls info from a nested table where, for example, an individual "key, value" pair has an ID number of a civ or a city or a trade-route as the "key", and the "value" is in fact another table of data.
Specifically what you are doing here:
Code:
for [COLOR="Blue"]v[/COLOR] in tplayer:Cities() do
You are telling lua to run through all the player's cities, performing actions on each individual city as the loop progresses from city to city, and while this loop is running each individual city will be referred to as
v so far as the instructions on what to do for each city is concerned.
I can state anything I want for the
? in this sort of construction:
Code:
for [COLOR="Blue"]?[/COLOR] in tplayer:Cities() do
so any of these would work:
Code:
function OnThePlayerNextTurn (iPlayer)
local tplayer = Players[iPlayer]
if tplayer:IsMinorCiv() or tplayer:IsBarbarian()
then return end
if not tplayer:IsAlive()
then return end
for pCity in tplayer:Cities() do
if (pCity:GetPopulation() >= 5) then
pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 1)
elseif (pCity:GetPopulation() < 5) then
pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 0)
end
end
end
GameEvents.PlayerDoTurn.Add(OnThePlayerNextTurn)
or
Code:
function OnThePlayerNextTurn (iPlayer)
local tplayer = Players[iPlayer]
if tplayer:IsMinorCiv() or tplayer:IsBarbarian()
then return end
if not tplayer:IsAlive()
then return end
for city in tplayer:Cities() do
if (city:GetPopulation() >= 5) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 1)
elseif (city:GetPopulation() < 5) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 0)
end
end
end
GameEvents.PlayerDoTurn.Add(OnThePlayerNextTurn)
or
Code:
function OnThePlayerNextTurn (iPlayer)
local tplayer = Players[iPlayer]
if tplayer:IsMinorCiv() or tplayer:IsBarbarian()
then return end
if not tplayer:IsAlive()
then return end
for Cheeseburger in tplayer:Cities() do
if (Cheeseburger:GetPopulation() >= 5) then
Cheeseburger:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 1)
elseif (Cheeseburger:GetPopulation() < 5) then
Cheeseburger:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 0)
end
end
end
GameEvents.PlayerDoTurn.Add(OnThePlayerNextTurn)
or
Code:
function OnThePlayerNextTurn (iPlayer)
local HamSandwiches = Players[iPlayer]
if HamSandwiches:IsMinorCiv() or HamSandwiches:IsBarbarian()
then return end
if not HamSandwiches:IsAlive()
then return end
for Lettuce in HamSandwiches:Cities() do
if (Lettuce:GetPopulation() >= 5) then
Lettuce:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 1)
elseif (Lettuce:GetPopulation() < 5) then
Lettuce:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 0)
end
end
end
GameEvents.PlayerDoTurn.Add(OnThePlayerNextTurn)
Both the way you are referring to a player and the way you are referring to a player's cities are variables that can be defined in pretty much any way you want -- you just have to remember within a single function to always refer to them in the same way once you define them.
--------------------------------------------------------------------------------
BTW, GetPlayer() is a function that is defined within that tutorial and will not be available to you in the context of your lua file. You would need to add it to your code in order for your code to work
Code:
function GetPlayer ()
local iPlayerID = Game.GetActivePlayer();
if (iPlayerID < 0) then
dprint("Error - player index not correct");
return nil;
end
if (not Players[iPlayerID]:IsHuman()) then
return nil;
end;
return Players[iPlayerID];
end
but there is yet another problem for you in that
dprint is yet another function that only exists within the context of file
TutorialChecks.lua, so you would also need
Code:
function dprint(msg)
if (ShowDebugMessages) then
print(msg);
end
end
which leads to yet another issue in that variable
ShowDebugMessages is also not defined within your code, so then you also need
Code:
local ShowDebugMessages = Game.IsTutorialLogging();
and then you would need to alter it to read "true" or "false" depending on whether you want your lua script to print debug error messages you place within your code.
But you really don't need any of this because
GameEvents.PlayerDoTurn directly gives you the player ID# of each player that is being processed while turn processing is being performed. All you need to do is sort out whether the current player is the player you are interested in.
-------------------------------------------------------------------------------------------------
Using the existing Firaxis code is a good method in many cases to see how different things are/can-be done in lua, but you have to look also for all these interlocking functions and variables to see how they work before you know if you can directly copy a piece of code, or are better served using a bit of Firaxis code as a template to understand how to structure your commands to get a similar effect.
-------------------------------------------------------------------------------------------------
I would try as this, which also eliminates the uneeded "elseif.....then" portion of the code. The population of the city is either going to be ">= 5" or "else" it is not, so there is no need for an additional "elseif" check:
Code:
function OnThePlayerNextTurn (iPlayer)
local tplayer = Players[iPlayer]
if tplayer:IsMinorCiv() or tplayer:IsBarbarian()
then return end
if not tplayer:IsAlive()
then return end
for pCity in tplayer:Cities() do
if (pCity:GetPopulation() >= 5) then
pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 1)
else
pCity:SetNumRealBuilding(GameInfoTypes["BUILDING_MONUMENT"], 0)
end
end
end
GameEvents.PlayerDoTurn.Add(OnThePlayerNextTurn)