Python arrays

Joined
Jul 5, 2004
Messages
23,562
Location
Canberra, Australia
I am getting no errors but nothing is happening either.

In caveman2Cosmos we have hundreds of buildings. On the pedia page for Bonuses there are three panels that show something to do with buildings. Each panel loops through the building list to find those buildings that belong in that panel. I thought that to improve efficiency I should go through the buildings once creating an array for each panel to use. However I get nothing.

Old code for one panel
Code:
	def placeSource(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_RESOURCE_SOURCE", ()), "", False, True, self.X_YIELD_PANE, self.Y_YIELD_PANE, self.W_YIELD_PANE, self.H_YIELD_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
		bonusInfo = gc.getBonusInfo(self.iBonus)

		for iBuilding in range(gc.getNumBuildingInfos()):
			info = gc.getBuildingInfo(iBuilding)
			bShow = (info.getFreeBonus() == self.iBonus)
			if (not bShow):
				for i in range(info.getNumExtraFreeBonuses()):
					if (info.getExtraFreeBonus(i) == self.iBonus):
						bShow = True
						break
			
			if (bShow):
				screen.attachImageButton( panelName, "", gc.getBuildingInfo(iBuilding).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, iBuilding, 1, False )

new code for setting up the array and populating it
Code:
	def parsAllBuildings(self):
		self.aSourceOfBonus = {}
		i = 0
		bonusInfo = gc.getBonusInfo(self.iBonus)
				
		for iBuilding in range(gc.getNumBuildingInfos()):
			buildingInfo = gc.getBuildingInfo(iBuilding)
			bShow = False

			if bonusInfo.getConstAppearance() > 0:
				if (buildingInfo.getFreeBonus() == self.iBonus):
					self.aSourceOfBonus.append( iBuilding )
				else:
					for i in range(buildingInfo.getNumExtraFreeBonuses()):
						if (buildingInfo.getExtraFreeBonus(i) == self.iBonus):
							self.aSourceOfBonus.append( iBuilding )
							break

New code for the panel
Code:
	def placeSource(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_RESOURCE_SOURCE", ()), "", False, True, self.X_YIELD_PANE, self.Y_YIELD_PANE, self.W_YIELD_PANE, self.H_YIELD_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
		bonusInfo = gc.getBonusInfo(self.iBonus)

		 for iBuilding in self.aSourceOfBonus:
			 screen.attachImageButton( panelName, "", gc.getBuildingInfo(iBuilding).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, iBuilding, 1, False )

Can anyone see what it is that I have done wrong? Actual code attached.
 
All I get from downloading is just attachment.php so can't view it :D
You might as well put the whole relevant codes in spoiler
 
whole code
Code:
# Sid Meier's Civilization 4
# Copyright Firaxis Games 2005

#
# Sevopedia 2.3
#   sevotastic.blogspot.com
#   sevotastic@yahoo.com
#
# additional work by Gaurav, Progor, Ket, Vovan, Fitchn, LunarMongoose
# see ReadMe for details
#

from CvPythonExtensions import *
import CvUtil
import ScreenInput
import SevoScreenEnums
import string

gc = CyGlobalContext()
ArtFileMgr = CyArtFileMgr()
localText = CyTranslator()

class SevoPediaBonus:

	def __init__(self, main):
		self.iBonus = -1
		## Buildings and Units only show up once in this page even if they could be in each pane.
		## They only show in the most important to this context
		self.aVicinityBuildings = {}
		self.aRequiresBuildings = {}
		self.aEffectedBuildings = {}
		self.aSourceOfBonus = {}
		self.aRequiresUnits = {}
		self.aEffectedUnits = {}
		self.top = main

		self.X_BONUS_PANE = self.top.X_PEDIA_PAGE
		self.Y_BONUS_PANE = self.top.Y_PEDIA_PAGE
		self.W_BONUS_PANE = self.top.W_PEDIA_PAGE / 2 - 5
		self.H_BONUS_PANE = 116

		self.W_ICON = 100
		self.H_ICON = 100
		self.X_ICON = self.X_BONUS_PANE + (self.H_BONUS_PANE - self.H_ICON) / 2
		self.Y_ICON = self.Y_BONUS_PANE + (self.H_BONUS_PANE - self.H_ICON) / 2
		self.ICON_SIZE = 64

		self.X_STATS_PANE = self.X_BONUS_PANE + 110
		self.Y_STATS_PANE = self.Y_BONUS_PANE + 33
		self.W_STATS_PANE = 240
		self.H_STATS_PANE = 200

		self.X_BONUS_ANIMATION = self.X_BONUS_PANE + self.W_BONUS_PANE + 10
		self.Y_BONUS_ANIMATION = self.Y_BONUS_PANE + 7
		self.W_BONUS_ANIMATION = self.top.R_PEDIA_PAGE - self.X_BONUS_ANIMATION 
		self.H_BONUS_ANIMATION = self.H_BONUS_PANE
		self.X_ROTATION_BONUS_ANIMATION = -20
		self.Z_ROTATION_BONUS_ANIMATION = 30
		self.SCALE_ANIMATION = 0.7

		# Yield pane is used for Yields for Map Resources and Sources for manufactured and culture resources
		self.X_YIELD_PANE = self.X_BONUS_PANE
		self.W_YIELD_PANE = self.W_BONUS_PANE
		self.Y_YIELD_PANE = self.Y_BONUS_PANE + self.H_BONUS_PANE + 10
		self.H_YIELD_PANE = 110

		self.X_EFFECTS_PANE = self.X_BONUS_ANIMATION
		self.W_EFFECTS_PANE = self.W_BONUS_ANIMATION
		self.Y_EFFECTS_PANE = self.Y_YIELD_PANE
		self.H_EFFECTS_PANE = self.H_YIELD_PANE

		self.X_REQUIRES = self.X_BONUS_PANE
		self.W_REQUIRES = self.W_BONUS_PANE
		self.Y_REQUIRES = self.Y_YIELD_PANE + self.H_YIELD_PANE + 10
		self.H_REQUIRES = 110

		self.X_BUILDINGS = self.X_BONUS_ANIMATION
		self.W_BUILDINGS = self.W_BONUS_ANIMATION
		self.Y_BUILDINGS = self.Y_REQUIRES
		self.H_BUILDINGS = self.H_REQUIRES

		self.X_ALLOWS_PANE = self.X_BONUS_PANE
		self.W_ALLOWS_PANE = self.top.R_PEDIA_PAGE - self.X_ALLOWS_PANE
		self.Y_ALLOWS_PANE = self.Y_REQUIRES + self.H_REQUIRES + 10
		self.H_ALLOWS_PANE = 110

		self.X_HISTORY_PANE = self.X_ALLOWS_PANE
		self.W_HISTORY_PANE = self.W_ALLOWS_PANE
		self.Y_HISTORY_PANE = self.Y_ALLOWS_PANE + self.H_ALLOWS_PANE + 10
		self.H_HISTORY_PANE = self.top.B_PEDIA_PAGE - self.Y_HISTORY_PANE



	def interfaceScreen(self, iBonus):
		self.iBonus = iBonus
		screen = self.top.getScreen()

		screen.addPanel( self.top.getNextWidgetName(), "", "", False, False, self.X_BONUS_PANE, self.Y_BONUS_PANE, self.W_BONUS_PANE, self.H_BONUS_PANE, PanelStyles.PANEL_STYLE_BLUE50)
		screen.addPanel(self.top.getNextWidgetName(), "", "", False, False, self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, PanelStyles.PANEL_STYLE_MAIN)
		screen.addDDSGFC(self.top.getNextWidgetName(), gc.getBonusInfo(self.iBonus).getButton(), self.X_ICON + self.W_ICON/2 - self.ICON_SIZE/2, self.Y_ICON + self.H_ICON/2 - self.ICON_SIZE/2, self.ICON_SIZE, self.ICON_SIZE, WidgetTypes.WIDGET_GENERAL, -1, -1 )
		screen.addBonusGraphicGFC(self.top.getNextWidgetName(), self.iBonus, self.X_BONUS_ANIMATION, self.Y_BONUS_ANIMATION, self.W_BONUS_ANIMATION, self.H_BONUS_ANIMATION, WidgetTypes.WIDGET_GENERAL, -1, -1, self.X_ROTATION_BONUS_ANIMATION, self.Z_ROTATION_BONUS_ANIMATION, self.SCALE_ANIMATION, True)

		## The original code goes through the building list for each pane that has a building in it. 
		## Same for units. It is better to only go through once to create a set of lists of the relevant buildings and units.
		# self.parsAllBuildings()
		# self.parsAllUnits()
		
		self.placeStats()
		if gc.getBonusInfo(self.iBonus).getConstAppearance() > 0:
			self.placeYield()
		else:
			self.placeSource()
		self.placeRequires()
		self.placeBuildings()
		self.placeAllows()
		self.placeEffects()
		self.placeHistory()

	def parsAllBuildings(self):
		i = 0
		bonusInfo = gc.getBonusInfo(self.iBonus)
				
		for iBuilding in range(gc.getNumBuildingInfos()):
			buildingInfo = gc.getBuildingInfo(iBuilding)
			bShow = False

			if bonusInfo.getConstAppearance() > 0:
				if (buildingInfo.getFreeBonus() == self.iBonus):
					self.aSourceOfBonus.append( iBuilding )
				else:
					for i in range(buildingInfo.getNumExtraFreeBonuses()):
						if (buildingInfo.getExtraFreeBonus(i) == self.iBonus):
							self.aSourceOfBonus.append( iBuilding )
							break

			
			if buildingInfo.getPrereqVicinityBonus() == self.iBonus :
				self.aVicinityBuildings[iBuilding] = iBuilding
				bShow = True
			else:
				if buildingInfo.getPrereqAndBonus() == self.iBonus :
					self.aRequiresBuildings[iBuilding] = iBuilding
					bShow = True
				else:
					j = 0
					while (not bShow and j < gc.getNUM_BUILDING_PREREQ_OR_BONUSES()):
						if (buildingInfo.getPrereqOrBonuses(j) == self.iBonus):
							self.aRequiresBuildings[iBuilding] = iBuilding
							bShow = True
						j += 1
			
			if (not bShow) and (buildingInfo.getBonusHealthChanges(self.iBonus) != 0 or buildingInfo.getBonusHappinessChanges(self.iBonus) != 0 or buildingInfo.getBonusProductionModifier(self.iBonus) != 0):
				self.aEffectedBuildings[iBuilding] = True
				bShow = True
			else:
				for eYield in range(YieldTypes.NUM_YIELD_TYPES):
					if (buildingInfo.getBonusYieldModifier(self.iBonus, eYield) != 0):
						self.aEffectedBuildings[iBuilding] = iBuilding
						bShow = True
						break
				
			# for eCommerce in range(YieldTypes.NUM_COMMERCE_TYPES):
				# if (buildingInfo.getBonusCommerceModifier(self.iBonus, eCommerce) > 0):
				
	
	def parsAllUnits(self):
		i = 0

	def placeStats(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addListBoxGFC(panelName, "", self.X_STATS_PANE, self.Y_STATS_PANE, self.W_STATS_PANE, self.H_STATS_PANE, TableStyles.TABLE_STYLE_EMPTY)
		screen.enableSelect(panelName, False)
		bonusInfo = gc.getBonusInfo(self.iBonus)
		for k in range(YieldTypes.NUM_YIELD_TYPES):
			iYieldChange = bonusInfo.getYieldChange(k)
			if (iYieldChange != 0):
				if (iYieldChange > 0):
					sign = "+"
				else:
					sign = ""
				szYield = (u"%s: %s%i " % (gc.getYieldInfo(k).getDescription(), sign, iYieldChange))
				screen.appendListBoxString(panelName, u"<font=3>" + szYield.upper() + (u"%c" % gc.getYieldInfo(k).getChar()) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)

		iHappy = bonusInfo.getHappiness()
		if not iHappy == 0:
			sign = "+"
			if iHappy < 0:
				sign = ""
			if gc.getBonusInfo(self.iBonus).getConstAppearance() > 0:
				screen.appendListBoxString( panelName, u"%s%i%c " % (sign, iHappy, CyGame().getSymbolID(FontSymbols.HAPPY_CHAR)) + localText.getText("TXT_KEY_PEDIA_WITH_IMPROVEMENT_AND_ROUTE", ()) + u"", WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
			else:
				screen.appendListBoxString( panelName, u"%s%i%c " % (sign, iHappy, CyGame().getSymbolID(FontSymbols.HAPPY_CHAR)) + u"", WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )

		iHealth = bonusInfo.getHealth()
		if not iHealth == 0:
			sign = "+"
			if iHealth < 0:
				sign = ""
			if gc.getBonusInfo(self.iBonus).getConstAppearance() > 0:
				screen.appendListBoxString( panelName, u"%s%i%c " % (sign, iHealth, CyGame().getSymbolID(FontSymbols.HEALTHY_CHAR)) + localText.getText("TXT_KEY_PEDIA_WITH_IMPROVEMENT_AND_ROUTE", ()) + u"", WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
			else:
				screen.appendListBoxString( panelName, u"%s%i%c " % (sign, iHealth, CyGame().getSymbolID(FontSymbols.HEALTHY_CHAR)) + u"", WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )



	def placeYield(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_CATEGORY_IMPROVEMENT", ()), "", True, True, self.X_YIELD_PANE, self.Y_YIELD_PANE, self.W_YIELD_PANE, self.H_YIELD_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
		bonusInfo = gc.getBonusInfo(self.iBonus)
		for j in range(gc.getNumImprovementInfos()):
			bFirst = True
			szYield = u""
			bEffect = False
			for k in range(YieldTypes.NUM_YIELD_TYPES):
				iYieldChange = gc.getImprovementInfo(j).getImprovementBonusYield(self.iBonus, k)
				if (iYieldChange != 0):
					bEffect = True
					iYieldChange += gc.getImprovementInfo(j).getYieldChange(k)
					if (bFirst):
						bFirst = False
					else:
						szYield += ", "
					if (iYieldChange > 0):
						sign = "+"
					else:
						sign = ""
					szYield += (u"%s%i%c" % (sign, iYieldChange, gc.getYieldInfo(k).getChar()))
			if (bEffect):
				childPanelName = self.top.getNextWidgetName()
				screen.attachPanel(panelName, childPanelName, "", "", False, False, PanelStyles.PANEL_STYLE_EMPTY)
				screen.attachLabel(childPanelName, "", "  ")
				screen.attachImageButton(childPanelName, "", gc.getImprovementInfo(j).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_IMPROVEMENT, j, 1, False )
				screen.attachLabel(childPanelName, "", szYield)

	def placeSource(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_RESOURCE_SOURCE", ()), "", False, True, self.X_YIELD_PANE, self.Y_YIELD_PANE, self.W_YIELD_PANE, self.H_YIELD_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
		bonusInfo = gc.getBonusInfo(self.iBonus)

		for iBuilding in range(gc.getNumBuildingInfos()):
			info = gc.getBuildingInfo(iBuilding)
			bShow = (info.getFreeBonus() == self.iBonus)
			if (not bShow):
				for i in range(info.getNumExtraFreeBonuses()):
					if (info.getExtraFreeBonus(i) == self.iBonus):
						bShow = True
						break
			
			if (bShow):
				screen.attachImageButton( panelName, "", gc.getBuildingInfo(iBuilding).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, iBuilding, 1, False )

		# for iBuilding in self.aSourceOfBonus:
			# screen.attachImageButton( panelName, "", gc.getBuildingInfo(iBuilding).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, iBuilding, 1, False )



	def placeEffects(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_EFFECTS", ()), "", True, False,
				 self.X_EFFECTS_PANE, self.Y_EFFECTS_PANE, self.W_EFFECTS_PANE, self.H_EFFECTS_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
		listName = self.top.getNextWidgetName()
		screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
		screen.enableSelect(listName, False)
		bonusInfo = gc.getBonusInfo(self.iBonus)

		for iBuilding in range(gc.getNumBuildingInfos()):
			info = gc.getBuildingInfo(iBuilding)
			name = info.getText()
			iHealth = info.getBonusHealthChanges(self.iBonus)
			if iHealth != 0:
				sign = "+"
				if iHealth < 0:
					sign = ""
				screen.appendListBoxString( listName, u"%s%i%c %s" % (sign, iHealth, CyGame().getSymbolID(FontSymbols.HEALTHY_CHAR), name), WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
			
			iHappy = info.getBonusHappinessChanges(self.iBonus)
			if iHappy != 0:
				if not iHappy == 0:
					sign = "+"
					if iHappy < 0:
						sign = ""
				screen.appendListBoxString( listName, u"%s%i%c %s" % (sign, iHappy, CyGame().getSymbolID(FontSymbols.HAPPY_CHAR), name), WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
			
			iProd = info.getBonusProductionModifier(self.iBonus)
			if iProd != 0:
				szProd = localText.getText("TXT_KEY_PEDIA_BUILDING_BONUS_PROD1",()) + u" %s %d " % (name, iProd) + localText.getText("TXT_KEY_PEDIA_BUILDING_BONUS_PROD2",()) + u""
				screen.appendListBoxString( listName, szProd, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )

			for eYield in range(YieldTypes.NUM_YIELD_TYPES):
				iYieldChange = info.getBonusYieldModifier(self.iBonus, eYield)
				if (iYieldChange != 0):
					if (iYieldChange > 0):
						sign = "+"
					else:
						sign = ""
					szYield = (u"%s%i%%%c %s" % (sign, iYieldChange, gc.getYieldInfo(eYield).getChar(), name))
					screen.appendListBoxString( listName, szYield, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )

				
			# for eCommerce in range(YieldTypes.NUM_COMMERCE_TYPES):
				# if (info.getBonusCommerceModifier(self.iBonus, eCommerce) > 0):
			



	def placeRequires(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_REQUIRES", ()), "", False, True, self.X_REQUIRES, self.Y_REQUIRES, self.W_REQUIRES, self.H_REQUIRES, PanelStyles.PANEL_STYLE_BLUE50 )
		screen.attachLabel(panelName, "", "  ")
		iRevealTech = gc.getBonusInfo(self.iBonus).getTechReveal()
		iTradeTech = gc.getBonusInfo(self.iBonus).getTechCityTrade()

		if (iRevealTech == iTradeTech) and (iRevealTech > -1):
			screen.attachImageButton( panelName, "", gc.getTechInfo(iRevealTech).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iRevealTech, 1, False )
			screen.attachLabel(panelName, "", u"(" + localText.getText("TXT_KEY_PEDIA_BONUS_APPEARANCE_AND_TRADE", ()) + u")")
		else:
			if (iRevealTech > -1):
				screen.attachImageButton( panelName, "", gc.getTechInfo(iRevealTech).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iRevealTech, 1, False )
				screen.attachLabel(panelName, "", u"(" + localText.getText("TXT_KEY_PEDIA_BONUS_APPEARANCE", ()) + u")")
			if (iTradeTech > -1):
				screen.attachImageButton( panelName, "", gc.getTechInfo(iTradeTech).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iTradeTech, 1, False )
				screen.attachLabel(panelName, "", u"(" + localText.getText("TXT_KEY_PEDIA_BONUS_TRADE", ()) + u")")



	def placeHistory(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName,localText.getText("TXT_KEY_CIVILOPEDIA_HISTORY", ()), "", True, True, self.X_HISTORY_PANE, self.Y_HISTORY_PANE, self.W_HISTORY_PANE, self.H_HISTORY_PANE, PanelStyles.PANEL_STYLE_BLUE50)
		screen.attachLabel(panelName, "", "  ")
		textName = self.top.getNextWidgetName()
		screen.addMultilineText( textName, gc.getBonusInfo(self.iBonus).getCivilopedia(), self.X_HISTORY_PANE + 15, self.Y_HISTORY_PANE + 40, self.W_HISTORY_PANE - (30), self.H_HISTORY_PANE - (15 * 2) - 25, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)



	def placeBuildings(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_CATEGORY_BUILDING", ()), "", False, True, self.X_BUILDINGS, self.Y_BUILDINGS, self.W_BUILDINGS, self.H_BUILDINGS, PanelStyles.PANEL_STYLE_BLUE50 )
		screen.attachLabel(panelName, "", "  ")
		for iBuilding in range(gc.getNumBuildingInfos()):
			info = gc.getBuildingInfo(iBuilding)
			bShow = ( info.getBonusHealthChanges(self.iBonus) > 0
					or info.getBonusHappinessChanges(self.iBonus) > 0
					or info.getBonusProductionModifier(self.iBonus) > 0
					or info.getPrereqAndBonus() == self.iBonus)
			if (not bShow):
				for eYield in range(YieldTypes.NUM_YIELD_TYPES):
					if (info.getBonusYieldModifier(self.iBonus, eYield) > 0):
						bShow = True
						break
			if not bShow:
				j = 0
				while (not bShow and j < gc.getNUM_BUILDING_PREREQ_OR_BONUSES()):
					if (info.getPrereqOrBonuses(j) == self.iBonus):
						bShow = True
					j += 1
			
			if (bShow):
				screen.attachImageButton( panelName, "", gc.getBuildingInfo(iBuilding).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, iBuilding, 1, False )

				
	def placeAllows(self):
		screen = self.top.getScreen()
		panelName = self.top.getNextWidgetName()
		screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_ALLOWS", ()), "", False, True, self.X_ALLOWS_PANE, self.Y_ALLOWS_PANE, self.W_ALLOWS_PANE, self.H_ALLOWS_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
		screen.attachLabel(panelName, "", "  ")
		for eLoopUnit in range(gc.getNumUnitInfos()):
			bFound = False
			if (eLoopUnit >= 0):
				if (gc.getUnitInfo(eLoopUnit).getPrereqAndBonus() == self.iBonus):
					bFound = True	
				else:
					j = 0
					while (not bFound and j < gc.getNUM_UNIT_PREREQ_OR_BONUSES()):
						if (gc.getUnitInfo(eLoopUnit).getPrereqOrBonuses(j) == self.iBonus):
							bFound = True
						j += 1
			if bFound:
				screen.attachImageButton( panelName, "", gc.getUnitInfo(eLoopUnit).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_UNIT, eLoopUnit, 1, False )



	def handleInput (self, inputClass):
		return 0

It is the commented out bit in the placeSource which is not working. I put it back to the working version . It only works in C2C though because of the new tags.
 
So what error is displayed, or what is the outcome?
 
No errors and nothing displayed. So no outcome when I try and use the arrays. It works fine otherwise. I'll get some screen shots to show you.
 
These are the results without and with arrays. The without works as there are buildings shown in the Source box.
 

Attachments

  • without array.jpg
    without array.jpg
    243.8 KB · Views: 83
  • with array.jpg
    with array.jpg
    234.8 KB · Views: 69
Code:
if gc.getBonusInfo(self.iBonus).getConstAppearance() > 0:
	self.placeYield()
else:
	self.placeSource()

Code:
def placeSource(self):
	for iBuilding in self.aSourceOfBonus:

Code:
if bonusInfo.getConstAppearance() > 0:
	if (buildingInfo.getFreeBonus() == self.iBonus):
		self.aSourceOfBonus.append( iBuilding )
	else:
		for i in range(buildingInfo.getNumExtraFreeBonuses()):
			if (buildingInfo.getExtraFreeBonus(i) == self.iBonus):
				self.aSourceOfBonus.append( iBuilding )
				break

self.placeSource() is activated only when bonusInfo.getConstAppearance() <= 0.
However, items are added into self.aSourceOfBonus only when bonusInfo.getConstAppearance() > 0.

Obviously when self.placeSource() is activated, self.aSourceOfBonus will always be an empty list.
 
No that was not the full problem as fixing that and another thing in the same area has not solved the problem. :(

Code:
		for iBuilding in range(gc.getNumBuildingInfos()):
			buildingInfo = gc.getBuildingInfo(iBuilding)

			if bonusInfo.getConstAppearance() == 0:
				if (buildingInfo.getFreeBonus() == self.iBonus):
					self.aSourceOfBonus.append( iBuilding )
				for i in range(buildingInfo.getNumExtraFreeBonuses()):
					if (buildingInfo.getExtraFreeBonus(i) == self.iBonus):
						self.aSourceOfBonus.append( iBuilding )
						break

bonusInfo.getConstAppearance() can only be zero or greater but I tried with <= just in case ad still no results.
 
No that was not the full problem as fixing that and another thing in the same area has not solved the problem. :(

Try adding this simple line to the code:

Code:
for iBuilding in range(gc.getNumBuildingInfos()):
	[COLOR="Red"]if (iBuilding != -1):[/COLOR]
		buildingInfo = gc.getBuildingInfo(iBuilding)
 
Back
Top Bottom