Well I've been plugging away and making progress..
I'm a newb... looking at all the lua scripts, I thought that necessarily had to be encapsulated in a function, so I did.
That was a mistake, it seems, and I removed the function from my code... it was not called by any other script in any case.
Using database logs, I also determined that minor civ players were not being called upon... perhaps because they do not have leaders (when I called them, using code that would call all civs including minors, their cities and "leader" never showed up in the print output. I may have to figure what to do about that later.
So going on...
Using the print function as was suggested, I was able to correct some mistakes in the code... this is what I now have:
Code:
-- Lua Script1
-- Author: Craig and Nancy
-- DateCreated: 7/21/2012 8:14:37 AM
--------------------------------------------------------------
-- Enumerate Cities with Confucianism
for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
local pPlayer = Players[iPlayer] print (pPlayer:GetName())
if pPlayer:IsEverAlive() then
-- Enumerate cities
for cityIndex = 0, pPlayer:GetNumCities() - 1, 1 do
local city = pPlayer:GetCityByID(cityIndex) print (city:GetName())
-- City exists and has the proper name?
if city ~= nil and city:GetName() == "Roskilde" then
print ("it works for Roskilde")
elseif city ~= nil and city:GetName() == "Oslo" then
print ("and it works for Oslo")
elseif city ~= nil and city:GetName() == "Nidaros" then
print ("and it works for Nidaros")
-- Add Religion
--city:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"])
break
end
end
end
end
However, there is a problem. Civ 5 crashes at this point. It iterates through all instance, then it just stops.
I suspect I need to put in some command or other that tells the script to stop running once all, or the last city I am looking for, are found.
Here is the portion of the database log that is relevant... notice how it hits each leader than proceeds through that civ's cities, then does the next. Oddly, some cities are missing... Haakon is missing two cities, for instance, after Nidaros is found. The other sample civs have all of their cities found. I wonder if it is relevant that Haakon is also the last player in the search scheme.
Anyhow, it then crashes at that point. My print functions show where it has found the appropriate cities.
My question is, how do I tell the script to stop coding and go on to the next part before it crashes?
I think that is the problem since the last portion:
elseif city ~= nil and city:GetName() == "Nidaros" then
print ("and it works for Nidaros")
seems to have caused some trouble (it did not complete going through all of its cities but stopped upon finding the target).
I notice some script have a command like: return city. I'll try that to see if it might work.
Bye the way, thank-you for all the advice. I am becoming more aware of how I can track things down if an error occurs. I hope to go to the well, so to speak, less often as I learn more about the commands and such.