What's wrong about this code?

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,132
Location
The Kingdom of New Zealand
I'm having some trouble getting this code to function:

Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(function(iPlayer)
local pPlayer = Players[iPlayer];
	if pPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_RUSSIA_NICHOLAS"] then
		for iCity in pPlayer:Cities() do
			local ProductionBoost = (iCity:GetProduction() + iCity:GetFaithPerTurn())
			iCity:SetBuildingProduction(ProductionBoost)
		end
	end
end)

I'm not sure what I'm doing wrong, as it had worked for Wonder Production. But because Wonder Production doesn't have a SetWonderProduction command (rather, ChangeWonderProduction, which means the boost will exponentially increase every turn), I'll have to settle with general building production.

Because the logs do not yield any errors, I must ask here. Any indication as to what I'm doing wrong would be appreciated.
 
SetBuildingProduction() accepts two parameters (BuildingType, int).

Also aren't you looking for ChangeBuildingProduction(BuildingType, int)?

Also just another thing, iCity is misleading, the city is a pointer (or instance...?) of a CvCity should it should be labeled pCity (not like it matters, but you're not calling functions on an integer, you're calling it on a pointer.
 
There's no "XyzWonderProduction" methods on cities, because wonders are just special types of building.

If you're trying to increase wonder production per turn by the amount of faith a city is generating, the logic / pseudo-code is

if IsWonder(pCity:GetProductionBuilding()) then
pCity:ChangeProduction(pCity:GetFaithPerTurn())
end

where the IsWonder(iBuilding) function needs to check that iBuilding is not -1, then lookup the class of the building and check if the MaxGlobalInstances is 1
 
SetBuildingProduction() accepts two parameters (BuildingType, int).

Also aren't you looking for ChangeBuildingProduction(BuildingType, int)?

Also just another thing, iCity is misleading, the city is a pointer (or instance...?) of a CvCity should it should be labeled pCity (not like it matters, but you're not calling functions on an integer, you're calling it on a pointer.

ChangeBuildingProduction would increase building production exponentially each turn, so that's no good.

Thanks for pointing out that the identifiers shouldn't be so arbitrary. I hadn't really thought about it, as I was basing this code off of someone elses'.

There's no "XyzWonderProduction" methods on cities, because wonders are just special types of building.

If you're trying to increase wonder production per turn by the amount of faith a city is generating, the logic / pseudo-code is

if IsWonder(pCity:GetProductionBuilding()) then
pCity:ChangeProduction(pCity:GetFaithPerTurn())
end

where the IsWonder(iBuilding) function needs to check that iBuilding is not -1, then lookup the class of the building and check if the MaxGlobalInstances is 1

Thank you. I got it working how I wanted.
 
Back
Top Bottom