Great Person error

I'm not familiar with the GreatPersonMod, but I can give you some ideas concerning the Python code displayed in your post. (I don't know how familiar you are with Python. If I'm stating something that is already obvious to you - I apologize.)

The interfaceScreen method is assuming that the the key stored in iData is already in the dictionary CvGreatPersonModEventManager.g_dict, but the dictionary is empty.

There are several ways to go about solving this:

1. Find out why the dictionary is empty and fix the problem there. That problem would be located somewhere elese in your code.

2. Add a line that checks if iData is in the dictionary - if it isn't then don't display the great person screen. That line would look something like this:
if iData in CvGreatPersonModEventManager.g_dict:
"Do the code listed in your post."
else:
"Don't draw the screen and exit."

3. You probably don't want to do this, but the third option would be to use the default option of the pop command. Like this:
pUnit, iPlayer, pCity = d.pop(iData, ( defaultUnit, defaultPlayer, defaultCity ))
If iData isn't in the dictionary, then the default values would be used. The default values would have to be valid unit, player, and city objects from your mod.
 
To say it in an easier way: We need all lines with CvGreatPersonModEventManager.g_dict
to say anything more.

This is the only line there with something like that??

Code:
def interfaceScreen (self, iData):

		d = CvGreatPersonModEventManager.g_dict
		pUnit, iPlayer, pCity = d.pop(iData)
		player = gc.getPlayer(iPlayer)
 
There should be code in CvGreatPersonEventManager that fills g_dict before calling the interfaceScreen() function to pop up the screen.
 
There should be code in CvGreatPersonEventManager that fills g_dict before calling the interfaceScreen() function to pop up the screen.

Didnt see anything, this is the file:

Spoiler :
Code:
#
# GreatPersonMod BTS
# CvGreatPersonModEventManager
# 

from CvPythonExtensions import *

import CvUtil
import CvEventManager
import sys
import PyHelpers
import CvGreatPersonScreen
import RandomNameUtils
import CvConfigParser
# Change the value to enable or disable the features from the Great Person Mod.
# Default value is true
g_bGreatPersonModFeaturesEnabled = true

gc = CyGlobalContext()

PyPlayer = PyHelpers.PyPlayer

g_iCount = 0     # autoincrement global used as the primary key for dictionary
g_dict = dict()  # holds information transferred from here to CvGreatPersonScreen.py

class CvGreatPersonModEventManager:

	def __init__(self, eventManager):

		GreatPerson(eventManager)

class AbstractGreatPerson(object):

	def __init__(self, eventManager, *args, **kwargs):
		super(AbstractGreatPerson, self).__init__(*args, **kwargs)

class GreatPerson(AbstractGreatPerson):

	def __init__(self, eventManager, *args, **kwargs):
		super(GreatPerson, self).__init__(eventManager, *args, **kwargs)

		eventManager.addEventHandler("greatPersonBorn", self.onGreatPersonBorn)

		self.eventMgr = eventManager

		# Begin Test Code
		""" # Uncomment this block to enable test code
		eventManager.addEventHandler("kbdEvent", self.onKbdEvent)

	# Test (ok cheat...) code to make sure that we can go through the vanilla great person
	# names and test the random names.
	## Changed event from just clicking mouse to hitting ALT-SHIFT-G. Test code not multiplayer compatible.
	## def onMouseEvent(self, argsList):
	def onKbdEvent(self, argsList):
		eventType,key,mx,my,px,py = argsList

		if(not g_bGreatPersonModFeaturesEnabled):
			return

		if ( eventType == self.eventMgr.EventKeyDown ):
			theKey=int(key)
			
			# Check if ALT + Shift + G was hit
			if (theKey == int(InputTypes.KB_G) and self.eventMgr.bAlt and self.eventMgr.bShift):	
				gc.getActivePlayer().getCapitalCity().createGreatPeople(gc.getInfoTypeForString("UNIT_GENERAL"), False, False)
				return 1
			
			# Check if CTRL + Shift + G was hit
			if (theKey == int(InputTypes.KB_G) and self.eventMgr.bCtrl and self.eventMgr.bShift):	
				gc.getActivePlayer().getCapitalCity().createGreatPeople(gc.getInfoTypeForString("UNIT_GREAT_SPY"), False, False)
				return 1
		return 0
		"""
		# End Test Code


	def onGreatPersonBorn(self, argsList):
		'Great Person Born'

		if(not g_bGreatPersonModFeaturesEnabled):
			return
		
		pUnit, iPlayer, pCity = argsList
		player = gc.getPlayer(iPlayer)
        
		# Check if we should even show the popup:
		if pUnit.isNone() or pCity.isNone():
			return
		
		#CvUtil.pyPrint("Great Person Born: Name:<%s> Player:<%s> City:<%s>"%(pUnit.getNameNoDesc(), player.getName(), pCity.getName()))
		    
		#If Person doesn't have unique name, give him a random one
		if(len(pUnit.getNameNoDesc()) == 0):
			iCivilizationType = player.getCivilizationType()
			pUnit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))

		#Show fancy lil popup if a human got the great person:
		if player.isHuman():
		
			global g_dict
			global g_iCount
			
			g_dict[g_iCount] = (pUnit, iPlayer, pCity)
			
			#CvUtil.pyPrint("Great Person Born 2: Name:<%s> iPlayer:<%d> City:<%s>"%(g_dict[g_iCount][0].getNameNoDesc(), g_dict[g_iCount][1], g_dict[g_iCount][2].getName()))
			
			popupInfo = CyPopupInfo()
			popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
			popupInfo.setData1(g_iCount)
			g_iCount += 1
			popupInfo.setText(u"showGreatPersonScreen")
			popupInfo.addPopup(iPlayer)

Also can i get some advice on this? Anything is better than nothing.

http://forums.civfanatics.com/showpost.php?p=8328058&postcount=11
 
do a search for g_dict and see what you come up with, there should be somewhere that defines what this is. What we are seeing is that g_dict when it is being used, doesn't make any sense for what it's being used for, so where is it being defined?

Edit: Oh, ninjad, looks like stuff above my level anyway...
 
do a search for g_dict and see what you come up with, there should be somewhere that defines what this is. What we are seeing is that g_dict when it is being used, doesn't make any sense for what it's being used for, so where is it being defined?

Edit: Oh, ninjad, looks like stuff above my level anyway...

OK, in
GreatPersonScreen:

Code:
def interfaceScreen (self, iData):

		d = CvGreatPersonModEventManager.g_dict
		pUnit, iPlayer, pCity = d.pop(iData)
		player = gc.getPlayer(iPlayer)

in GreatPersonModEvent:

Code:
g_iCount = 0     # autoincrement global used as the primary key for dictionary
g_dict = dict()  # holds information transferred from here to CvGreatPersonScreen.py

Code:
global g_dict
			global g_iCount
			
			g_dict[g_iCount] = (pUnit, iPlayer, pCity)
			
			#CvUtil.pyPrint("Great Person Born 2: Name:<%s> iPlayer:<%d> City:<%s>"%(g_dict[g_iCount][0].getNameNoDesc(), g_dict[g_iCount][1], g_dict[g_iCount][2].getName()))

Thats all the python. None listed anyplace else.
 
:confused: sure, that the intendation is right?

The problem atm is, that there's nothing in the dictionary, but in the function itself is a check for an empty dictionary, so there shouldn't be a way to get this error.

Was it maybe a special situation? Or just a normal "GP-birth"?
 
:confused: sure, that the intendation is right?

The problem atm is, that there's nothing in the dictionary, but in the function itself is a check for an empty dictionary, so there shouldn't be a way to get this error.

Was it maybe a special situation? Or just a normal "GP-birth"?

I believe it was a Birth as you put it?
 
:confused: sorry, i don't understand that sentence.
Did you just put it with the worldbuilder somewhere?

You asked "Or just a normal "GP-birth"? and i said Birth?

And no i dont cheat when playing, so i dont go into the WB, sorry.;)
 
OK got another GP error:

Traceback (most recent call last):

File "CvScreensInterface", line 200, in showGreatPersonScreen

File "CvGreatPersonScreen", line 58, in interfaceScreen

KeyError: 'pop(): dictionary is empty'
ERR: Python function showGreatPersonScreen failed, module CvScreensInterface


Code:
def interfaceScreen (self, iData):

		d = CvGreatPersonModEventManager.g_dict
		[B]pUnit, iPlayer, pCity = d.pop(iData)[/B]
		player = gc.getPlayer(iPlayer)
 
Did you install the separate graphics pack that contains all the pictures?

Infact i installed the old Amra one plus the Roamty one for pics.

Code:
# if there is a file in the GreatPeople directory with the name, we'll load it.
		szImageFilename = os.path.join(szArtPath, szImageName + ".dds")
		#CvUtil.pyPrint("Great Person Popup: Image Filename: " + szImageFilename)
		if not os.path.isfile(szImageFilename):
                        #if not, load the great "type of person" file
			szImageName = self.type2str(szUnitType)
			szImageFilename = os.path.join(szArtPath, szImageName + ".dds")
			if not os.path.isfile(szImageFilename):
                                #if not, load the great person file
				szImageName = "Great Person"
 
Back
Top Bottom