A stupid Python error that I can't figure out

RogerBacon

King
Joined
Nov 16, 2003
Messages
649
Here's the error:

===========================================
Traceback (most recent call last):

File "CvEventInterface", line 23, in onEvent

File "CvCustomEventManager", line 45, in handleEvent

File "CvEventManager", line 177, in handleEvent

File "CvCustomEventManager", line 108, in onBeginGameTurn

File "Shogun", line 28, in onBeginGameTurn

RuntimeError: unidentifiable C++ exception
ERR: Python function onEvent failed, module CvEventInterface

============================================

Here's the relevant part of my "Shogun.py" file from the beginning:

Code:
from CvPythonExtensions import *
import CvUtil
import PyHelpers		# LOQ
import Popup as PyPopup
import pickle			# LOQ 2005-10-12

# globals
gc = CyGlobalContext()
PyPlayer = PyHelpers.PyPlayer	# LOQ
PyInfo = PyHelpers.PyInfo
theGame = CyGame()
theGameSpeedInfo = CvGameSpeedInfo()


class Shogun:						
	def onBeginGameTurn(self, argsList):
		'Called at the beginning of a game turn'
		iPlayer = argsList
		for iPlayer in range(gc.getMAX_PLAYERS()):
			pPlayer = gc.getPlayer(iPlayer)
			# change this numer to alter the chance of getting an experiece point. A unit has 1 out of [this value] chance of getting an exp each turn
			# for example, if you set it to 10 a unit has a 1 in 10 chance of getting an exp point each turn. 
			#Setting it to 1 means units gain an exp point every turn (1 in 1 chance)
			barracksChance = 12
			drydockChance = 12
			# Units with exp higher than this number will not gain any more exp from a barracks or drydock.
			barracksMaxExp = 8
			drydockMaxExp = 8
			myCivName = pPlayer.getCivilizationDescriptionKey()
			message1 = myCivName
			#CyInterface().addImmediateMessage(message1,"")
			CvUtil.pyPrint(message1)

The line that causes the problem is:
myCivName = pPlayer.getCivilizationDescriptionKey()

Now, the code works fine but it gives me that error. I know it's working because the log shows it prints "TXT_KEY_CIV_JAPAN_DESC" and the rest of the script continues to execute.

In my customEventInterface.py I have:

Code:
def onBeginGameTurn(self, argsList):
		'Called at the beginning of the end of each turn'
		self.parent.onBeginGameTurn(self, argsList);
		#INSERT MODS
		sho.onBeginGameTurn(argsList)

If I change it to:
sho.onBeginGameTurn(self, argsList)

then I get the error message:

onBeginGameTurn() takes exactly 2 arguments (3 given)

Does anyone know what is causing this error?

Roger Bacon
 
Roger,

If I am reading your code right you are trying to get the list of players currently in the game right? If you are you should be using the method:
getCivPlayerList() from the PyGame class in the PyHelpers.py file instead. Calling the getMAX_PLAYERS() method will retrieve what the maximum amount of player possible is, right now in my test game there are 2 active players but calling getMAX_PLAYERS() returns 19. When you call the getCivilizationDescriptionKey() method you are doing so on an null object which is the root of your issue.

So basically you need to do this:


... some python code ...
...
...

class Shogun:
[TAB]def onBeginGameTurn(self, argsList):
[TAB][TAB]'Called at the beginning of a game turn'
[TAB][TAB]playerList = theGame.getCivPlayerList()
[TAB][TAB]for player in range(len(playerList)):
[TAB][TAB][TAB]pPlayer = gc.getPlayer(player.getID())
 
Back
Top Bottom