How does iPlayer:GetCities():Members() return a function?

CivilizationAce

Warlord
Joined
Jan 17, 2017
Messages
236
I really hate not having incomplete reference material :(

I figured iPlayer:GetCities():Members() would return a table.

I want to use the result field in pairs(), so a function won't do. I'm plain confused. Please help.

P.S. iPlayer is definitely a Player.
 
Code:
for i, pCity in pPlayer:GetCities():Members() do
   -- do something with pCity
end

you can use whatever name you want to a player table, the code will work, but people will expect iPlayer to be a player ID when reading your code.
 
there are good tutorials for civ5, here is a good one about naming, see here: https://forums.civfanatics.com/threads/lua-basic-modding-guide-for-civ5.533853/#post-13447053

just remember that the function names exposed to lua have changed between civ5 and civ6, refers to the sheet in the Lua object thread for a (maybe not complete) list of civ6 exposed functions, and use any good text editor to do a filtered search on lua files in the civ6 folder and subfolders for example of use.
 
I figured iPlayer:GetCities():Members() would return a table.
It returns an iterator that allows you to go through elements using 'for' statement.


for i, pCity in pPlayer:GetCities():Members() do -- do something with pCity end
Can you explain pls why there are two types of iterators? The above example (basically all :Members() functons) use 2 variables. However when using GameInfo you need only 1, like below:

Code:
for row in GameInfo.Technologies() do
  -- code
end

Is it just like Firaxis implemented those or is there some language peculiarity that I am not aware of?
 
Is there a guide to what prefixes to use?
There many places where you can read about Hungarian notation (i.e. what @Gedemon posted). I can give you quick version that I'm using.
b - boolean
i - integer number
f - float number
e - enumeration (integer but each number has a meaning)
s - string
t - table
p - pointer (it's technically a table but it's meaning in the code is usually different)
 
It returns an iterator that allows you to go through elements using 'for' statement.



Can you explain pls why there are two types of iterators? The above example (basically all :Members() functons) use 2 variables. However when using GameInfo you need only 1, like below:

Code:
for row in GameInfo.Technologies() do
  -- code
end

Is it just like Firaxis implemented those or is there some language peculiarity that I am not aware of?
Firaxis made special implementations for both conditions, as they did in civ5. But in civ5 they implemented as
Code:
for pItem in pPlayer:Cities() do
for pItem in pPlayer:Units() do
This gave more-direct access to the list of player units and cities directly as Player functions rather than needing to do the (rather kludgey IMO civ6 method) of 1st getting the Player:GetCities() object and then actually getting the list of cities in the GetCities() object.

IN Civ5 you could also do DB.Querry statements as an inherent part of the GameInfo.TableName() iterator.
Code:
	for row in GameInfo.Buildings("Type='BUILDING_ZANBIL'") do
		tCultureDollopWonders[row.ID] = 1
	end
and
Code:
for row in GameInfo.Civilization_UnitClassOverrides("CivilizationType='" .. sCivilizationName .. "'") do
whereas in civ6 so far as I am aware these efficiency methods are not implemented and we still have to iterate through the entire table (potentially) before we can find the one item we are interested in from the given table.
 
Top Bottom