Randomising City Names.

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,132
Location
The Kingdom of New Zealand
The intention is to pick a random city from this custom table. The rest of the code which does the choosing only ever works for the last city value. So this is evidently not the way to do it :/

Code:
for row in GameInfo.Civilization_JFD_ColonialCityNames() do
   local civType = row.CivilizationType
     if colonialPlayer:GetCivilizationType() == GameInfoTypes[civType] then
         local colonialCities = {}
          table.insert(colonialCities, row.CityName)
           for i, v in ipairs(colonialCities) do
                print(i)
                 print(v)
            end
print("random name " .. colonialCities[math.random(#colonialCities)])

The index is always 1. A misunderstanding of the use of tables, perhaps, but I've never added values from a custom table before, and any examples or tutorials that I've come across haven't been much use (although one example does similar to what I'm trying to do, so I don't know). So any help would be appreciated, and much time saving :)
 
Code:
local colonialCities = {}
for row in GameInfo.Civilization_JFD_ColonialCityNames() do
   local civType = row.CivilizationType
     if colonialPlayer:GetCivilizationType() == GameInfoTypes[civType] then
          table.insert(colonialCities, row.CityName)
	end
end
           for i, v in ipairs(colonialCities) do
                print(i, v)
            end
print("random name " .. colonialCities[math.random(#colonialCities)])
"Table = {}" defines table, but also clears table if it already exists.
 
Back
Top Bottom