BUG error onTechAquired from goodyhut

Joined
Jul 5, 2004
Messages
23,562
Location
Canberra, Australia
I am getting the following error, in PythonErr.log, when a good hut gives me a free tech.

Code:
Traceback (most recent call last):
  File "BugEventManager", line 363, in _handleDefaultEvent
  File "autologEventManager", line 657, in onGoodyReceived
KeyError: 12

It appears to give me this only on new techs I have added recently. Does this error mean I have missed something when I put the techs in?
 
I forgot to mention that I did check the XML for a tech which worked with one that gave the above error and I could not see anything obvious. So I am hoping that the KeyError:12 means something from your side which will provide a clue as to how I fix things on my side.
 
It means your mod has more things you can get from goody huts than BtS does.

BtS has a nothing option plus 12 other goody types, numbered from 0 to 11. Your onGoodyReceived is getting called when granting option type 12 which the autolog feature doesn't know anything about. It is trying to look up the mapping for the key "12" in the dictionary it uses to store the good hut related messages.

The mod ought to have a file called CIV4GoodyInfo.xml in its GameInfo folder. This is where the various types are defined. The dictionary definition in autologEventManager.py that starts on line 642 needs to match what is in that XML file with the first GoodyInfo definition in the XML being for key 0.

Now that you have pointed this out, I have noticed that the Final Frontier Plus merge with BUG has this problem too...
 
I fixed that problem now I am getting a divide by zero on line 702 autologEventManager.py. I am assuming it is because I am in an anarchy at the time. I can fix it in my copy but it probably should be fixed in general.
 
The question is "what line 702?"

I'm guessing it is line 702 in your now modified file, which has a different line 702 than the original.
(Line 702 in the original file that comes with BUG 4.4 is a blank line.

Since we are posting about problems with autologEventManager.py...

It uses a hardcoded value of 5 for the number of civic categories. Any mod, such as Final Frontier Plus, that does not have 5 will have problems. More than 5 and it won't pay any attention to the extras. Less than 5 and it has more serious problems as it runs off the end of the array in the DLL when using the CyPlayer.getCivics function.

For the Final Frontier Plus BUG merge I added a self.iNumCivicOptions value in the initStuff function like so:
Code:
	def initStuff(self):
		#set up variables to hold stuff
		ziMaxCiv = gc.getGame().countCivPlayersEverAlive()
		self.iNumCivicOptions = gc.getNumCivicOptionInfos() # CivicOption bug fix
		self.CIVAttitude = [""] * ziMaxCiv * ziMaxCiv
		self.CIVCivics = [0] * ziMaxCiv * self.iNumCivicOptions # CivicOption bug fix
		self.CIVReligion = [-1] * ziMaxCiv
		self.CityWhipCounter = [0] * 1000
		self.CityConscriptCounter = [0] * 1000
and then referenced it everywhere it was using the hardcoded value of 5 for this, including in initStuf() itself where it was used to initialize the self.CICCivics array, as well as 6 other places.
Two places near the end of storeStuff:
Code:
		# store the civ's civics
		for iCiv in range(0, ziMaxCiv, 1):
			if PyPlayer(iCiv).isAlive():
				for iCivic in range(0, self.iNumCivicOptions, 1): # CivicOption bug fix
					zKey = self.iNumCivicOptions * iCiv + iCivic # CivicOption bug fix
					self.CIVCivics[zKey] = gc.getPlayer(iCiv).getCivics(iCivic)
two near the end of checkStuff:
Code:
				if (PyPlayer(iCiv).isAlive()
				and gc.getTeam(gc.getPlayer(iCiv).getTeam()).isHasMet(gc.getActivePlayer().getTeam())):
					for iCivic in range(0, self.iNumCivicOptions, 1): # CivicOption bug fix
						zKey = self.iNumCivicOptions * iCiv + iCivic # CivicOption bug fix
and two near the middle of dumpStuff:
Code:
			for iCivic in range(0, self.iNumCivicOptions, 1): # CivicOption bug fix
				zKey = self.iNumCivicOptions * iCiv + iCivic # CivicOption bug fix
				zsOldCiv = gc.getCivicInfo(self.CIVCivics[zKey]).getDescription()
				zsNewCiv = gc.getCivicInfo(gc.getPlayer(iCiv).getCivics(iCivic)).getDescription()
				message = "Civics, %s, %s, %s" % (zsCiv, zsOldCiv, zsNewCiv)
				Logger.writeLog(message)
 
The question is "what line 702?"

I'm guessing it is line 702 in your now modified file, which has a different line 702 than the original.
(Line 702 in the original file that comes with BUG 4.4 is a blank line.

Of course - duh!:blush: It is in onTechSelected
Code:
	def onTechSelected(self, argsList):
		if (AutologOpt.isLogTechnology()):
			iTechType, iPlayer = argsList
			if iPlayer == CyGame().getActivePlayer():
				researchProgress = gc.getTeam(gc.getPlayer(iPlayer).getTeam()).getResearchProgress(gc.getPlayer(iPlayer).getCurrentResearch())
				overflowResearch = (gc.getPlayer(iPlayer).getOverflowResearch() * gc.getPlayer(iPlayer).calculateResearchModifier(gc.getPlayer(iPlayer).getCurrentResearch()))/100
				researchCost = gc.getTeam(gc.getPlayer(iPlayer).getTeam()).getResearchCost(gc.getPlayer(iPlayer).getCurrentResearch())
				researchRate = gc.getPlayer(iPlayer).calculateResearchRate(-1)
				if researchRate == 0:
					message = "Divide by zero in autologEventManager onTechSelected"
				else:
					zTurns = (researchCost - researchProgress - overflowResearch) / researchRate + 1
					message = BugUtil.getText("TXT_KEY_AUTOLOG_RESEARCH_BEGUN", (PyInfo.TechnologyInfo(iTechType).getDescription(), zTurns))
				Logger.writeLog(message, vColor="Green")

One thing I still forgot to do was add in the game text after fixing the goody hut dictionary.
 
Yes I had a ";" instead of a ":" in my code above, I fixed it;)

God-Emperor, when I put your changes in for the civics fix I get the following error
Code:
Traceback (most recent call last):
  File "BugEventManager", line 363, in _handleDefaultEvent
  File "autologEventManager", line 342, in onGameStart
  File "autologEventManager", line 1468, in storeStuff
TypeError: object does not support item assignment

which is in the bold line in
Code:
		# store the civ's civics
		for iCiv in range(0, ziMaxCiv, 1):
			if PyPlayer(iCiv).isAlive():
				for iCivic in range(0, self.iNumCivicOptions, 1): # CivicOption bug fix
					zKey = self.iNumCivicOptions * iCiv + iCivic # CivicOption bug fix
[B][COLOR="Red"]					self.CIVCivics[zKey] = gc.getPlayer(iCiv).getCivics(iCivic)
[/COLOR][/B]		return 0

which is one line you didn't change:confused:

Pressing enter and I get a similar end of turn error
Code:
Traceback (most recent call last):
  File "BugEventManager", line 363, in _handleDefaultEvent
  File "autologEventManager", line 352, in onEndGameTurn
  File "autologEventManager", line 1531, in checkStuff
TypeError: unsubscriptable object

I suspect I am starting with an older version of auto logger.
 
For the Final Frontier Plus BUG merge I added a self.iNumCivicOptions value in the initStuff function
Yeah - that was me with the hard coded '5'. Isn't there a game option that gives you the number of civic columns? I'm assuming that the F3 screen uses it to draw its civic information.
 
God-Emperor, when I put your changes in for the civics fix I get the following error
Code:
Traceback (most recent call last):
  File "BugEventManager", line 363, in _handleDefaultEvent
  File "autologEventManager", line 342, in onGameStart
  File "autologEventManager", line 1468, in storeStuff
TypeError: object does not support item assignment

which is in the bold line in
Code:
		# store the civ's civics
		for iCiv in range(0, ziMaxCiv, 1):
			if PyPlayer(iCiv).isAlive():
				for iCivic in range(0, self.iNumCivicOptions, 1): # CivicOption bug fix
					zKey = self.iNumCivicOptions * iCiv + iCivic # CivicOption bug fix
[B][COLOR="Red"]					self.CIVCivics[zKey] = gc.getPlayer(iCiv).getCivics(iCivic)
[/COLOR][/B]		return 0

which is one line you didn't change:confused:

Pressing enter and I get a similar end of turn error
Code:
Traceback (most recent call last):
  File "BugEventManager", line 363, in _handleDefaultEvent
  File "autologEventManager", line 352, in onEndGameTurn
  File "autologEventManager", line 1531, in checkStuff
TypeError: unsubscriptable object

I suspect I am starting with an older version of auto logger.

It sounds like the version you are using doesn't have the self.CIVCivics list.
Merging with a different version could be a little harder - you pretty much need to go through and substitute the self.iNumCivicOptions wherever it is using "5" in a civics category related context.


Yeah - that was me with the hard coded '5'. Isn't there a game option that gives you the number of civic columns? I'm assuming that the F3 screen uses it to draw its civic information.

The fix I posted (for the version that comes with BUG v4.4) uses this:
Code:
self.iNumCivicOptions = gc.getNumCivicOptionInfos() # CivicOption bug fix
which uses the right number, whatever it may be, as defined in the XML.
 
The fix I posted (for the version that comes with BUG v4.4) uses this:
Code:
self.iNumCivicOptions = gc.getNumCivicOptionInfos() # CivicOption bug fix
which uses the right number, whatever it may be, as defined in the XML.
Ok, cool. I didn't look at your code too hard and missed that part. :goodjob:
 
Top Bottom