[PYTHON] Error: Cycity has no attribute hasbuilding Oo

Burlwood

Chieftain
Joined
Sep 5, 2007
Messages
7
Location
Germany
I got a little Prob, and i dont know whats the reason for this error message.

Here is the basic code, pretty simple:


Code:
	def cannotConstruct(self,argsList):
		pCity = argsList[0]
		eBuilding = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]
		if pCity.getOwner() == CyGame().getActivePlayer():
			if eBuilding == gc.getInfoTypeForString('BUILDING_BARRACKS'):
				if pCity.hasBuilding(gc.getInfoTypeForString("BUILDING_OBELISK")):
					return True
		return False

I played around a bit, and i get this message with all boolean cycity commands i tested.
I also turned pCity from a cycity into a pycity. Didn't help, same error.


Any Ideas what could be going wrong?
 
Thx for fast reply.

This works. :)


Seems i was confused by the API. :undecide:
Now all other booleans also work.
 
If you're not afraid of the SDK you can see everything that is exposed to python in a few files. While their choice for function names don't always make sense you can usually figure out what it will do (like: isHasBuilding). Just take a peek in any Cy???Interface.cpp file, you'll see lines like:

python::def("cyIntRange", cyIntRange,"int (int iNum, int iLow, int iHigh)");

Note that python::def may be replaced by simply .def depending on which file you're in. Anyway, the first string in "" is the function name you'll use in Python, after that is the name of the C++ function within the DLL (typically the same) and last, also in "" is the return type and args for the python function. Remember that python always passes 'self' so in your example you have an object, pCity calling the function (method technically) on itself with pCity.isHasBuilding()

Anyway, it's pretty easy to get in there and look at whats available or to see whats causing you headaches if some bit of code isn't working.
 
Yeah.

I know the SDK a bit.
But i got no plan which function is in which file. :rolleyes:

So i searched the web for a Tool, helping me finding a string in all files of a subfolder.
And i found one.
Its called "Lookdisk" and its nice to search through all these xml files also. :)
 
I had the exact same issue, VERY strange that you say it's isHasBuilding as http://civilization4.net/files/modding/PythonAPI/index2.html says:
Code:
# BOOL hasBonus(BonusType iBonus)
bool - (BonusID) - is BonusID connected to the city?

You are probably right though. Gonna check and see for myself. Thanks for the help!

Btw, did this change with BtS or something?
 
Bonuses and Buildings are different :)

I don't think these changed with BtS, some new methods were added and a few old methods were exposed to python but with the exception of the new features there weren't too many significant changes, I don't recall seeing any changes in the method names.
 
Bonuses and Buildings are different :)

I don't think these changed with BtS, some new methods were added and a few old methods were exposed to python but with the exception of the new features there weren't too many significant changes, I don't recall seeing any changes in the method names.
Oh, yes, there were significant changes going from Vanilla => BtS. Not sure what exactly happened during the transition to or from Warlords though.
 
Top Bottom