Help with lua for coastal conditioned cities

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,132
Location
The Kingdom of New Zealand
I'm having some trouble understanding the problem with this:

Spoiler :
Code:
function OnCityCaptureComplete(iOldOwner, bIsCapital, iCityX, iCityY, iNewOwner, iPop, bConquest)
	local pNewOwner = Players[iNewOwner];
	if(pNewOwner:GetCivilizationType() == GameInfoTypes["CIVILIZATION_ITALY"]) then
		if pNewOwner ~= pOldOwner then 
		local city = Map.GetPlot(iX, iY):GetPlotCity();
		if city:IsCoastal() then 
		-- Adjust the size of the bonus based on the game speed
		local bonusGoldenAge = 50;
		local speedGoldenAgePercent = GameInfo.GameSpeeds[Game:GetGameSpeedType()].GoldenAgePercent;
		local adjustedGoldenAgebonus = (bonusGoldenAge * speedGoldenAgePercent) / 100;
		pNewOwner:ChangeGoldenAgeProgressMeter(adjustedGoldenAgebonus);
		end
		end
	end
end

It works perfectly fine when I don't check if the city is a costal city, so obviously this is where I'm failing to do it correctly.

In the log, it states: Italian Trait.lua:11: attempt to index local 'city' (a nil value)

I'm still warming up to lua, so if someone could explain the problem to me it would help immensely. Thanks.
 
function OnCityCaptureComplete(iOldOwner, bIsCapital, iCityX, iCityY, iNewOwner, iPop, bConquest)
...
local city = Map.GetPlot(iX, iY):GetPlotCity();

Those two arguments need to be the same. Copy-paste is probably the culprit.
 
Back
Top Bottom