@ LeeS:
Can you explain why this could fail ?
Because I am stupid and didn't look closely enough at the code shown. For some reason I kept seeing it as a PlayerDoTurn kind of thing, rather than just a loop through.
---------------------------------------------------------------------------------
63 is always the Barbarian player in lua. Unfortunately, because of the dreadful way they did WorldBuilder, Barbarians are always 22 (or 23 ?) in Worldbuilder, so we have that nice consistency going for us
----------------------------------------------------------------------------------
IsAlive() is better because it tells whether the player is still
currently part of the game. IsEverAlive() will be true if the player in question was
ever part of the current game.
-----------------------------------------------------------------------------------
This method:
Code:
gQActiveCivPlayerNames = {}
for i = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
local iSlot = PreGame.GetSlotStatus(i)
if iSlot == SlotStatus.SS_TAKEN or iSlot == SlotStatus.SS_COMPUTER then
local playerCivilizationID = Players[i]:GetCivilizationType()
local playerCivilizationName = GameInfo.Civilizations{ID=playerCivilizationID}().Type
table.insert(gQActiveCivPlayerNames, playerCivilizationName)
end
end
is an example not only of how to loop through the major players and only process the ones that are or were in-game, but also shows an example of how to "store" some critical piece of info in an lua-table to access it again later. This is much faster processing-wise than looking up the same data from the game's XML-tables every time you need to refer to that data. You wouldn't necessarily want the "Type" data, for example, but you might want some other piece of info, such as, say, the ArtStyle.
In my case I was interested in all the "CIVILIZATION_AMERICA", "CIVILIZATION_ARABIA", etc., names for civs that had at one point been active in the game, because I followed the loop shown with searching through an altered
<Unit_UniqueNames> XML-table that as a result of my mod now had 800+ names to sort through, each of which was assigned to a specific civilization.