python problem

mechaerik

Tuturuu!
Joined
Oct 28, 2008
Messages
7,064
Location
Los Angeles
I've been trying this for a while, but I can't seem to get it to work:
PHP:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())
		pCity = pPlot.getPlotCity()  ##added
## mechaerik START
		if (pCity.getNumRealBuilding(gc.getInfoTypeForString("BUILDING_PALACE")))>0:
						unit.changeExperience(2,100,False,False,False)
## mechaerik END
## mechaerik START
		if (gc.getPlayer(pCity.getOwner()).isCivic(gc.getInfoTypeForString("CIVIC_SLAVERY"))):
						unit.changeExperience(2,100,False,False,False)
## mechaerik END


The first one is me trying to make it so if theres a certain building (palace is a placeholder), a unit will spawn with more xp.
The second is basically the same, only with civics, not buildings.
Any obvious errors?
 
The city variable, which you directly get, is a city instance, so you don't have to do pCity = pPlot.getPlotCity(). No idea, why this doesn't throw an error, because you have no plot here -> because of this, i guess, your code doesn't work, because you don't get a valid city instace.
Just replace the pCity with city, and it should work.

Okay, besides, that in the first if clause the last bracket should be after the 1.
 
Top Bottom