• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

Help on something python- cveventmanager

anhu

Chieftain
Joined
Nov 21, 2005
Messages
21
I cannot get this to work:

Code:
		if (gc.getBuildingInfo(iBuildingType).getType() == "BUILDING_COAL_PLANT"):
			for i in range(gc.getNumBuildingInfos()):
				if (gc.getBuildingInfo(i).getType() == "BUILDING_NUCLEAR_PLANT"):
					pCity.setHasRealBuilding(i, False)
				if (gc.getBuildingInfo(i).getType() == "BUILDING_HYDRO_PLANT"):
					pCity.setHasRealBuilding(i, False)
		elif (gc.getBuildingInfo(iBuildingType).getType() == "BUILDING_NUCLEAR_PLANT"):
			for i in range(gc.getNumBuildingInfos()):
				if (gc.getBuildingInfo(i).getType() == "BUILDING_HYDRO_PLANT"):
					pCity.setHasRealBuilding(i, False)
				if (gc.getBuildingInfo(i).getType() == "BUILDING_COAL_PLANT"):
					pCity.setHasRealBuilding(i, False)
		elif (gc.getBuildingInfo(iBuildingType).getType() == "BUILDING_HYDRO_PLANT"):
			for i in range(gc.getNumBuildingInfos()):
				if (gc.getBuildingInfo(i).getType() == "BUILDING_NUCLEAR_PLANT"):
					pCity.setHasRealBuilding(i, False)
				if (gc.getBuildingInfo(i).getType() == "BUILDING_COAL_PLANT"):
					pCity.setHasRealBuilding(i, False)

This is supposed to let me switch between the 3 power plants the game offers (build a certain power plant, the previous power plant is removed). This is nearly identical to someone's upgradeable buildings demo in the mod comps section.

The fact that I'm asking for help should indicate that the python code does not work...

Any help would be appreciated =).
 
You must not be looking at your python exceptions, because you have the wrong function name. Please be sure to turn on python exceptions and logging. Then you will see that there is no function setHasRealBuilding. The function you want is setNumRealBuilding(int buildingtype, int numbuildings). To remove a building, pass 0 for numbuildings.

Also, your code relies on loops and string comparisons, which is a little inefficient. I assume you are putting this in the onBuildingBuilt callback. You may want to try something like this:

pCity, iBuildingType = argslist
iNuke = gc.getInfoTypeForString("BUILDING_NUCLEAR_PLANT")
iCoal = gc.getInfoTypeForString("BUILDING_COAL_PLANT")
if iBuildingType == iNuke: pCity.setNumRealBuilding(iCoal, 0)
 
Much thanks =)

Forgive me for being so newbish, but I did not know there was a way to show these kinds of errors (until you told me there was a way to show my exceptions).
 
Back
Top Bottom