First, the error in the log is this:
Code:
function Muscogee_MicoScience(playerID)
print("Muscogee trait is active")
local player = Players[playerID]
if (player:IsEverAlive() and player:GetCivilizationType() == civilisationID) then
local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city), 3)
city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
else
if city:IsHasBuilding(buildingMuscogeeScienceID) then
city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
end
end
end
[COLOR="Red"] end
end[/COLOR]
You simply had too many
end statements.
BUT, I think there might be some other issues. Now, mind you, I haven't read through this entire thread, so maybe I don't understand the UA correctly, but is this function supposed to do the following: If a city has a outgoing traderoute, then a dummy building is constructed in that city. If the number of traderoutes increases, the number of the dummy building increases accordingly. But there's a minimum cap of 3 dummy buildings, so actually for 1-3 outgoing traderoute from a city,
3 dummy buildings are constructed, for 4 outgoing traderoutes from a city, 4 dummy buildings are constructed, etc. If there is no outgoing traderoutes, then all dummy buildings are deleted. Is this understood correctly?
If that is the case, I think there might be a few issues with the code. You have a function that counts the number of outgoing traderoutes from a specific city
Code:
Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city)
but the Muscogee_MicoScience function doesn't specify which city. I think you're missing a "for city in player:Cities() do" statement as you have in the Muscogee_MicoScienceCityView function. Anyways, try this:
Code:
function Muscogee_MicoScience(playerID)
local player = Players[playerID]
if player:IsEverAlive() and player:GetCivilizationType() == civilisationID then
print("Muscogee trait is active") -- only print statement if Muscogee is active
for city in player:Cities() do
if Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city) < 0 then -- checks if city has outgoing traderoutes
local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city), 3)
city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
else -- if don't think you need the "if city:IsHasBuilding(buildingMuscogeeScienceID) then" statement, since using if.. else..
city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
end
end
end
end
In the Muscogee_MicoScienceCityView() function, I think there might also be a problem. You have this
Code:
for city in player:Cities() do
local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(activePlayerID, city), 3)
city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
else
if city:IsHasBuilding(buildingMuscogeeScienceID) then
city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
end
end
I'm not sure, and as said I haven't tested it, but it looks like you're missing an
if statement to the
else statement. Maybe it should - as in the above function - be something like this:
Code:
function Muscogee_MicoScienceCityView()
local player = Players[playerID]
if (player:IsEverAlive() and player:GetCivilizationType() == civilisationID) then
for city in player:Cities() do
if Muscogee_GetNumTradeRoutesLeavingThisCity(playerID, city) < 0 then -- checks if city has outgoing traderoutes
local numMicoScience = mathMin(Muscogee_GetNumTradeRoutesLeavingThisCity(activePlayerID, city), 3)
city:SetNumRealBuilding(buildingMuscogeeScienceID, numMicoScience)
else
city:SetNumRealBuilding(buildingMuscogeeScienceID, 0)
end
end
end
end
I haven't looked through the rest as I know from experience, that trying to fix everything at once is never a good idea. So focus on these functions first, and then, when they are working correctly, then move on to the next functions (if there are even any errors in them).
Hopefully you can use this. But just beware, I'm not a very skilled modder, like, at all. Still trying to get a hang of lua myself, so I can't guarantee the above changes will do you any good.