View Full Version : A python exception I don't understand


Maniac
Feb 04, 2007, 05:44 AM
I can't get an event to work. Does anyone what's the problem with the last line of this event? A screenie with the python exception message is attached.

def onBeginPlayerTurn(self, argsList):
'Called at the beginning of a players turn'
iGameTurn, iPlayer = argsList
pPlayer = gc.getPlayer(iPlayer)
py = PyPlayer(iPlayer)

bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())

iTeam = gc.getTeam(bPlayer.getTeam())
if (iTeam.isHasTech(gc.getInfoTypeForString('TECH_HOR SEBACK_RIDING')) == False and iTeam.isHasTech(gc.getInfoTypeForString('TECH_BRON ZE_WORKING')) == False and iTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCH ERY')) == False and iTeam.isHasTech(gc.getInfoTypeForString('TECH_TRAC KING')) == False):
listTeams = []
for iPlayer2 in range(gc.getMAX_PLAYERS()):
pPlayer2 = gc.getPlayer(iPlayer2)
if (pPlayer2.isAlive() and iPlayer2 != iPlayer):
iTeam2 = pPlayer2.getTeam()
listTeams.append(gc.getTeam(iTeam2))
iCount = 0
for i in range(len(listTeams)):
if (listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_HORSEBACK _RIDING')) or listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_BRONZE_WO RKING')) or listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_ARCHERY') ) or listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_TRACKING' )) or listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_WAY_OF_TH E_FORESTS')) or listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_WAY_OF_TH E_EARTHMOTHER')) or listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_MESSAGE_F ROM_THE_DEEP')) or listTeams[i].isHasTech(gc.getInfoTypeForString('TECH_CONSTRUCT ION'))):
iCount = iCount + 1
if iCount >= 3:
PushTier2MilTech = [ 'TECH_HORSEBACK_RIDING','TECH_BRONZE_WORKING','TEC H_ARCHERY','TECH_TRACKING' ]
iRnd = CyGame().getSorenRandNum(len(PushTier2MilTech), "Maniac")
iTeam.setHasTech(gc.getInfoTypeForString(PushTier2 MilTech[iRnd]), True, bPlayer, False, True)

And does anyone know what bFirst is about?

VOID setHasTech(TechType eIndex, BOOL bNewValue, PlayerType ePlayer, BOOL bFirst, BOOL bAnnounce)
void (TechID, bNewValue, iPlayer, bFirst, bAnnounce)

http://forums.civfanatics.com/uploads/53302/pythonexception2.jpg

CyberChrist
Feb 04, 2007, 06:53 AM
Your variable bPlayer is the problem here. C++ is expecting that it contains an INT value with the player number (of the Barbarians), but you currently have it containing a reference to an instance of the CyPlayer class (of the Barbarians).

Changing the following line:
bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())

to:
bPlayer = gc.getBARBARIAN_PLAYER()

should do the trick.

CyberChrist
Feb 04, 2007, 07:04 AM
... or if you need the bPlayer as it was further down in the code then change:
iTeam.setHasTech(gc.getInfoTypeForString(PushTier2 MilTech[iRnd]), True, bPlayer, False, True)

to:
iTeam.setHasTech(gc.getInfoTypeForString(PushTier2 MilTech[iRnd]), True, bPlayer.getID(), False, True)

Maniac
Feb 04, 2007, 10:43 AM
Thanks. :D

Maniac
Feb 04, 2007, 07:55 PM
I'm having a problem with another event. The cause seems to be something similar, but I really can't figure out what I would have to put there instead. :( Especially since I've seen another event with these exact lines. It's again in the last line.

def onUnitBuilt(self, argsList):
'Unit Completed'
city = argsList[0]
unit = argsList[1]
player = PyPlayer(city.getOwner())
pPlayer = gc.getPlayer(unit.getOwner())

if pPlayer.isHuman() == False:
if unit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_ADEPT'):
unit.setHasPromotion(gc.getInfoTypeForString('PROM OTION_FREE_PROMOTION'), False)
Promotions = []
if pPlayer.getNumAvailableBonuses(gc.getInfoTypeForSt ring('BONUS_MANA_BODY')) == 1:
Promotions.append(gc.getInfoTypeForString('PROMOTI ON_BODY1'))
...
if pPlayer.getNumAvailableBonuses(gc.getInfoTypeForSt ring('BONUS_MANA_WATER')) == 1:
Promotions.append(gc.getInfoTypeForString('PROMOTI ON_WATER1'))
iRnd = CyGame().getSorenRandNum(len(Promotions), "Maniac")
unit.setHasPromotion(gc.getInfoTypeForString(Promo tions[iRnd]), True)

Gaurav
Feb 04, 2007, 10:19 PM
I'm having a problem with another event. The cause seems to be something similar, but I really can't figure out what I would have to put there instead. :( Especially since I've seen another event with these exact lines. It's again in the last line.

Try replacing
unit.setHasPromotion(gc.getInfoTypeForString(Promo tions[iRnd]), True)
with
unit.setHasPromotion(Promotions[iRnd], True)
since you have already been calling gc.getInfoTypeForString() on everything before putting it into the array.

Maniac
Feb 05, 2007, 04:57 PM
Wow you just made my day! (Or at least some worries this evening ;))