switchable state units

cpt.tripps.2012

Warlord
Joined
May 25, 2012
Messages
176
So I've been working on a squeal to deanej's Star trek mod for about 8 months now and it is almost ready to really go public (It's already semi-public).

One of the things I wanted to add was to be able to set the ships to GREEN/YELLOW/RED Alerts. But I am running into a bit of a bind in the python department.

In the original star trek mod there is a some code by TC01 that looks like this:

CvMainInterface.py
Spoiler :
Code:
#Added in Cloaking Devices -- TC01
					pUnit = g_pSelectedUnit
					iUnitType = pUnit.getUnitType()
					pUnitOwner = gc.getPlayer( pUnit.getOwner( ))
					pUnitTeam = gc.getTeam(pUnit.getOwner())
					if (pUnitOwner.isTurnActive( ) and pUnit.canMove()):
						if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_CLOAKING_DEVICE')) and not (gc.getUnitInfo(pUnit.getUnitType()).isNoCloaking() or pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK')) or pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_FIRE')))):
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('PROMOTION_CLOAK')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 660, 660, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
						if (pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK')) or pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_FIRE'))):
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('PROMOTION_CLOAK')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 661, 661, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
#End of Cloaking Device code
and
Spoiler :
Code:
#Added in Cloaking Devices -- TC01
		if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 660 and inputClass.getData2() == 660):
			self.iPushedButtonUnit = g_pSelectedUnit
			if(self.iPushedButtonUnit.getUnitType() == gc.getInfoTypeForString('UNIT_KLINGON_CHANG') or self.iPushedButtonUnit.getUnitType() == gc.getInfoTypeForString('UNIT_SCIMITAR')):
                                self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_FIRE'), true)
                        else:
                                self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK'), true)
			g_pSelectedUnit.changeMoves(60)
			CyAudioGame().Play2DSound('AS2D_CLOAK_ON')

		if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 661 and inputClass.getData2() == 661):
			self.iPushedButtonUnit = g_pSelectedUnit
			if(self.iPushedButtonUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_FIRE'))):
                                self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_FIRE'), false)
                        else:
                                self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK'), false)
			g_pSelectedUnit.changeMoves(60)
			CyAudioGame().Play2DSound('AS2D_CLOAK_OFF')
#End of Cloaking Device code -- TC01


and there is matching promotions;

CIV4PromotionInfos.xml
Spoiler :
Code:
<PromotionInfo>
			<Type>PROMOTION_CLOAK</Type>
			<Description>TXT_KEY_PROMOTION_CLOAK</Description>
			<Sound>AS2D_CLOAK_ON</Sound>
			<LayerAnimationPath>NONE</LayerAnimationPath>
			<PromotionPrereq>NONE</PromotionPrereq>
			<PromotionPrereqOr1>NONE</PromotionPrereqOr1>
			<PromotionPrereqOr2>NONE</PromotionPrereqOr2>
			<TechPrereq>NONE</TechPrereq>
			<StateReligionPrereq>NONE</StateReligionPrereq>
			<Invisible>NONE</Invisible>
			<bLeader>0</bLeader>
			<bBlitz>0</bBlitz>
			<bAmphib>0</bAmphib>
			<bRiver>0</bRiver>
			<bEnemyRoute>0</bEnemyRoute>
			<bAlwaysHeal>0</bAlwaysHeal>
			<bHillsDoubleMove>0</bHillsDoubleMove>
			<bImmuneToFirstStrikes>0</bImmuneToFirstStrikes>
			<bOnlyDefensive>1</bOnlyDefensive>
			<bCloaked>1</bCloaked>
			<iVisibilityChange>0</iVisibilityChange>
			<iMovesChange>-1</iMovesChange>
			<iMoveDiscountChange>0</iMoveDiscountChange>
			<iAirRangeChange>0</iAirRangeChange>
			<iInterceptChange>0</iInterceptChange>
			<iEvasionChange>0</iEvasionChange>
			<iWithdrawalChange>0</iWithdrawalChange>
			<iCargoChange>0</iCargoChange>
			<iCollateralDamageChange>0</iCollateralDamageChange>
			<iBombardRateChange>0</iBombardRateChange>
			<iFirstStrikesChange>0</iFirstStrikesChange>
			<iChanceFirstStrikesChange>0</iChanceFirstStrikesChange>
			<iEnemyHealChange>0</iEnemyHealChange>
			<iNeutralHealChange>0</iNeutralHealChange>
			<iFriendlyHealChange>0</iFriendlyHealChange>
			<iSameTileHealChange>0</iSameTileHealChange>
			<iAdjacentTileHealChange>0</iAdjacentTileHealChange>
			<iCombatPercent>0</iCombatPercent>
			<iCityAttack>0</iCityAttack>
			<iCityDefense>0</iCityDefense>
			<iHillsAttack>0</iHillsAttack>
			<iHillsDefense>0</iHillsDefense>
			<iKamikazePercent>0</iKamikazePercent>
			<iRevoltProtection>0</iRevoltProtection>
			<iCollateralDamageProtection>0</iCollateralDamageProtection>
			<iPillageChange>0</iPillageChange>
			<iUpgradeDiscount>0</iUpgradeDiscount>
			<iExperiencePercent>0</iExperiencePercent>
			<TerrainAttacks/>
			<TerrainDefenses/>
			<FeatureAttacks/>
			<FeatureDefenses/>
			<UnitCombatMods/>
			<DomainMods/>
			<TerrainDoubleMoves/>
			<FeatureDoubleMoves/>
			<UnitCombats>
			</UnitCombats>
			<HotKey/>
			<bAltDown>0</bAltDown>
			<bShiftDown>0</bShiftDown>
			<bCtrlDown>0</bCtrlDown>
			<iHotKeyPriority>0</iHotKeyPriority>
			<Button>,Art/Interface/Buttons/Tech/CloakingDevice.dds</Button>
		</PromotionInfo>
		<PromotionInfo>
			<Type>PROMOTION_CLOAK_FIRE</Type>
			<Description>TXT_KEY_PROMOTION_CLOAK</Description>
			<Sound>AS2D_CLOAK_ON</Sound>
			<LayerAnimationPath>NONE</LayerAnimationPath>
			<PromotionPrereq>NONE</PromotionPrereq>
			<PromotionPrereqOr1>NONE</PromotionPrereqOr1>
			<PromotionPrereqOr2>NONE</PromotionPrereqOr2>
			<TechPrereq>NONE</TechPrereq>
			<StateReligionPrereq>NONE</StateReligionPrereq>
			<Invisible>NONE</Invisible>
			<bLeader>0</bLeader>
			<bBlitz>0</bBlitz>
			<bAmphib>0</bAmphib>
			<bRiver>0</bRiver>
			<bEnemyRoute>0</bEnemyRoute>
			<bAlwaysHeal>0</bAlwaysHeal>
			<bHillsDoubleMove>0</bHillsDoubleMove>
			<bImmuneToFirstStrikes>0</bImmuneToFirstStrikes>
			<bCloaked>1</bCloaked>
			<iVisibilityChange>0</iVisibilityChange>
			<iMovesChange>0</iMovesChange>
			<iMoveDiscountChange>0</iMoveDiscountChange>
			<iAirRangeChange>0</iAirRangeChange>
			<iInterceptChange>0</iInterceptChange>
			<iEvasionChange>0</iEvasionChange>
			<iWithdrawalChange>0</iWithdrawalChange>
			<iCargoChange>0</iCargoChange>
			<iCollateralDamageChange>0</iCollateralDamageChange>
			<iBombardRateChange>0</iBombardRateChange>
			<iFirstStrikesChange>0</iFirstStrikesChange>
			<iChanceFirstStrikesChange>0</iChanceFirstStrikesChange>
			<iEnemyHealChange>0</iEnemyHealChange>
			<iNeutralHealChange>0</iNeutralHealChange>
			<iFriendlyHealChange>0</iFriendlyHealChange>
			<iSameTileHealChange>0</iSameTileHealChange>
			<iAdjacentTileHealChange>0</iAdjacentTileHealChange>
			<iCombatPercent>0</iCombatPercent>
			<iCityAttack>0</iCityAttack>
			<iCityDefense>0</iCityDefense>
			<iHillsAttack>0</iHillsAttack>
			<iHillsDefense>0</iHillsDefense>
			<iKamikazePercent>0</iKamikazePercent>
			<iRevoltProtection>0</iRevoltProtection>
			<iCollateralDamageProtection>0</iCollateralDamageProtection>
			<iPillageChange>0</iPillageChange>
			<iUpgradeDiscount>0</iUpgradeDiscount>
			<iExperiencePercent>0</iExperiencePercent>
			<TerrainAttacks/>
			<TerrainDefenses/>
			<FeatureAttacks/>
			<FeatureDefenses/>
			<UnitCombatMods/>
			<DomainMods/>
			<TerrainDoubleMoves/>
			<FeatureDoubleMoves/>
			<UnitCombats/>
			<HotKey/>
			<bAltDown>0</bAltDown>
			<bShiftDown>0</bShiftDown>
			<bCtrlDown>0</bCtrlDown>
			<iHotKeyPriority>0</iHotKeyPriority>
			<Button>,Art/Interface/Buttons/Tech/CloakingDevice.dds</Button>
		</PromotionInfo>

copies of the files are here: http://sourceforge.net/projects/startrekmod2/files/Patch%20files/

This works really well where if you hit the button it cloaks, hit it again and it decloaks. But these have a binary state, and what I need is a trinary state with three buttons for green/yellow/red. Ideally the active one greys out (or is brighter something like, basically a different image) and it switches to that promotion removing the other two promotions.

I know. Getting complicated. Anyway, I'm a bit lost here. I'm a pretty good coder but I'm having trouble understanding the CIV SDK (python is a bit foreign to me, but I think I understand it). If any one could help in anyway with this I'd be super grateful. And I hate to ask people to do my work for me, but If you would like to take this small code on for yourself, I'd of course happily give you credit as a coder on the project. I'm planning on having a full public announcement of the beta at the end of the month and this is really one of the last piece of the puzzle I'd like to have in place before I do.

Thanks in advance! (And of course any help at all will get you a special thanks in the credits)
 
Do you want that this also works via promotions? (don't think so)
Do you understand at least a bit of the Python code, which you've C&Ped?

In case yes: TC01 also made a tutorial about Python buttons, see here. It would probably be good if you read it and tested if before you try other things.
 
SWEET! That will help a lot! Thanks.

And I do think it has to be tied to the promotions because it changes the stats of the unit.

I added these buttons in CIV4ArtDefines_Interface.xml:
Spoiler :
Code:
<InterfaceArtInfo>
			<Type>INTERFACE_GREEN1</Type>
			<Path>Art/Interface/Buttons/Promotions/green1.dds</Path>
		</InterfaceArtInfo>
		<InterfaceArtInfo>
			<Type>INTERFACE_GREEN2</Type>
			<Path>Art/Interface/Buttons/Promotions/green2.dds</Path>
		</InterfaceArtInfo>
		<InterfaceArtInfo>
			<Type>INTERFACE_YELLOW1</Type>
			<Path>Art/Interface/Buttons/Promotions/yellow1.dds</Path>
		</InterfaceArtInfo>
		<InterfaceArtInfo>
			<Type>INTERFACE_YELLOW2</Type>
			<Path>Art/Interface/Buttons/Promotions/yellow2.dds</Path>
		</InterfaceArtInfo>
		<InterfaceArtInfo>
			<Type>INTERFACE_RED1</Type>
			<Path>Art/Interface/Buttons/Promotions/red1.dds</Path>
		</InterfaceArtInfo>
		<InterfaceArtInfo>
			<Type>INTERFACE_RED2</Type>
			<Path>Art/Interface/Buttons/Promotions/red2.dds</Path>
		</InterfaceArtInfo>
red1,yellow1, and green1 are for not-selected; and red2,yellow2, and green2 are for selected.

I Added these promotions to go with the buttons:
Spoiler :
Code:
<PromotionInfo>
			<Type>PROMOTION_GQ1</Type>
			<Description>Green Alert</Description>
			<Sound>AS2D_CLOAK_ON</Sound>
			<LayerAnimationPath>NONE</LayerAnimationPath>
			<PromotionPrereq>NONE</PromotionPrereq>
			<PromotionPrereqOr1>NONE</PromotionPrereqOr1>
			<PromotionPrereqOr2>NONE</PromotionPrereqOr2>
			<TechPrereq>NONE</TechPrereq>
			<StateReligionPrereq>NONE</StateReligionPrereq>
			<Invisible>NONE</Invisible>
			<bLeader>0</bLeader>
			<bBlitz>0</bBlitz>
			<bAmphib>0</bAmphib>
			<bRiver>0</bRiver>
			<bEnemyRoute>0</bEnemyRoute>
			<bAlwaysHeal>0</bAlwaysHeal>
			<bHillsDoubleMove>0</bHillsDoubleMove>
			<bImmuneToFirstStrikes>0</bImmuneToFirstStrikes>
			<bOnlyDefensive>0</bOnlyDefensive>
			<bCloaked>0</bCloaked>
			<iVisibilityChange>0</iVisibilityChange>
			<iMovesChange>1</iMovesChange>
			<iMoveDiscountChange>0</iMoveDiscountChange>
			<iAirRangeChange>0</iAirRangeChange>
			<iInterceptChange>0</iInterceptChange>
			<iEvasionChange>0</iEvasionChange>
			<iWithdrawalChange>0</iWithdrawalChange>
			<iCargoChange>0</iCargoChange>
			<iCollateralDamageChange>0</iCollateralDamageChange>
			<iBombardRateChange>0</iBombardRateChange>
			<iFirstStrikesChange>0</iFirstStrikesChange>
			<iChanceFirstStrikesChange>0</iChanceFirstStrikesChange>
			<iEnemyHealChange>0</iEnemyHealChange>
			<iNeutralHealChange>0</iNeutralHealChange>
			<iFriendlyHealChange>0</iFriendlyHealChange>
			<iSameTileHealChange>0</iSameTileHealChange>
			<iAdjacentTileHealChange>0</iAdjacentTileHealChange>
			<iCombatPercent>-30</iCombatPercent>
			<iCityAttack>0</iCityAttack>
			<iCityDefense>0</iCityDefense>
			<iHillsAttack>0</iHillsAttack>
			<iHillsDefense>0</iHillsDefense>
			<iKamikazePercent>0</iKamikazePercent>
			<iRevoltProtection>0</iRevoltProtection>
			<iCollateralDamageProtection>0</iCollateralDamageProtection>
			<iPillageChange>0</iPillageChange>
			<iUpgradeDiscount>0</iUpgradeDiscount>
			<iExperiencePercent>0</iExperiencePercent>
			<TerrainAttacks/>
			<TerrainDefenses/>
			<FeatureAttacks/>
			<FeatureDefenses/>
			<UnitCombatMods/>
			<DomainMods/>
			<TerrainDoubleMoves/>
			<FeatureDoubleMoves/>
			<UnitCombats>
			</UnitCombats>
			<HotKey/>
			<bAltDown>0</bAltDown>
			<bShiftDown>0</bShiftDown>
			<bCtrlDown>0</bCtrlDown>
			<iHotKeyPriority>0</iHotKeyPriority>
			<Button>,Art/Interface/Buttons/Tech/CloakingDevice.dds</Button>
		</PromotionInfo>
		<PromotionInfo>
			<Type>PROMOTION_GQ2</Type>
			<Description>Yellow Alert</Description>
			<Sound>AS2D_CLOAK_ON</Sound>
			<LayerAnimationPath>NONE</LayerAnimationPath>
			<PromotionPrereq>NONE</PromotionPrereq>
			<PromotionPrereqOr1>NONE</PromotionPrereqOr1>
			<PromotionPrereqOr2>NONE</PromotionPrereqOr2>
			<TechPrereq>NONE</TechPrereq>
			<StateReligionPrereq>NONE</StateReligionPrereq>
			<Invisible>NONE</Invisible>
			<bLeader>0</bLeader>
			<bBlitz>0</bBlitz>
			<bAmphib>0</bAmphib>
			<bRiver>0</bRiver>
			<bEnemyRoute>0</bEnemyRoute>
			<bAlwaysHeal>0</bAlwaysHeal>
			<bHillsDoubleMove>0</bHillsDoubleMove>
			<bImmuneToFirstStrikes>0</bImmuneToFirstStrikes>
			<bOnlyDefensive>0</bOnlyDefensive>
			<bCloaked>0</bCloaked>
			<iVisibilityChange>0</iVisibilityChange>
			<iMovesChange>0</iMovesChange>
			<iMoveDiscountChange>0</iMoveDiscountChange>
			<iAirRangeChange>0</iAirRangeChange>
			<iInterceptChange>0</iInterceptChange>
			<iEvasionChange>0</iEvasionChange>
			<iWithdrawalChange>0</iWithdrawalChange>
			<iCargoChange>0</iCargoChange>
			<iCollateralDamageChange>0</iCollateralDamageChange>
			<iBombardRateChange>0</iBombardRateChange>
			<iFirstStrikesChange>0</iFirstStrikesChange>
			<iChanceFirstStrikesChange>0</iChanceFirstStrikesChange>
			<iEnemyHealChange>0</iEnemyHealChange>
			<iNeutralHealChange>0</iNeutralHealChange>
			<iFriendlyHealChange>0</iFriendlyHealChange>
			<iSameTileHealChange>0</iSameTileHealChange>
			<iAdjacentTileHealChange>0</iAdjacentTileHealChange>
			<iCombatPercent>0</iCombatPercent>
			<iCityAttack>0</iCityAttack>
			<iCityDefense>0</iCityDefense>
			<iHillsAttack>0</iHillsAttack>
			<iHillsDefense>0</iHillsDefense>
			<iKamikazePercent>0</iKamikazePercent>
			<iRevoltProtection>0</iRevoltProtection>
			<iCollateralDamageProtection>0</iCollateralDamageProtection>
			<iPillageChange>0</iPillageChange>
			<iUpgradeDiscount>0</iUpgradeDiscount>
			<iExperiencePercent>0</iExperiencePercent>
			<TerrainAttacks/>
			<TerrainDefenses/>
			<FeatureAttacks/>
			<FeatureDefenses/>
			<UnitCombatMods/>
			<DomainMods/>
			<TerrainDoubleMoves/>
			<FeatureDoubleMoves/>
			<UnitCombats>
			</UnitCombats>
			<HotKey/>
			<bAltDown>0</bAltDown>
			<bShiftDown>0</bShiftDown>
			<bCtrlDown>0</bCtrlDown>
			<iHotKeyPriority>0</iHotKeyPriority>
			<Button>,Art/Interface/Buttons/Tech/CloakingDevice.dds</Button>
		</PromotionInfo>
		<PromotionInfo>
			<Type>PROMOTION_GQ3</Type>
			<Description>Red Alert</Description>
			<Sound>AS2D_CLOAK_ON</Sound>
			<LayerAnimationPath>NONE</LayerAnimationPath>
			<PromotionPrereq>NONE</PromotionPrereq>
			<PromotionPrereqOr1>NONE</PromotionPrereqOr1>
			<PromotionPrereqOr2>NONE</PromotionPrereqOr2>
			<TechPrereq>NONE</TechPrereq>
			<StateReligionPrereq>NONE</StateReligionPrereq>
			<Invisible>NONE</Invisible>
			<bLeader>0</bLeader>
			<bBlitz>0</bBlitz>
			<bAmphib>0</bAmphib>
			<bRiver>0</bRiver>
			<bEnemyRoute>0</bEnemyRoute>
			<bAlwaysHeal>0</bAlwaysHeal>
			<bHillsDoubleMove>0</bHillsDoubleMove>
			<bImmuneToFirstStrikes>0</bImmuneToFirstStrikes>
			<bOnlyDefensive>0</bOnlyDefensive>
			<bCloaked>0</bCloaked>
			<iVisibilityChange>0</iVisibilityChange>
			<iMovesChange>-1</iMovesChange>
			<iMoveDiscountChange>0</iMoveDiscountChange>
			<iAirRangeChange>0</iAirRangeChange>
			<iInterceptChange>0</iInterceptChange>
			<iEvasionChange>0</iEvasionChange>
			<iWithdrawalChange>0</iWithdrawalChange>
			<iCargoChange>0</iCargoChange>
			<iCollateralDamageChange>0</iCollateralDamageChange>
			<iBombardRateChange>0</iBombardRateChange>
			<iFirstStrikesChange>0</iFirstStrikesChange>
			<iChanceFirstStrikesChange>0</iChanceFirstStrikesChange>
			<iEnemyHealChange>0</iEnemyHealChange>
			<iNeutralHealChange>0</iNeutralHealChange>
			<iFriendlyHealChange>0</iFriendlyHealChange>
			<iSameTileHealChange>0</iSameTileHealChange>
			<iAdjacentTileHealChange>0</iAdjacentTileHealChange>
			<iCombatPercent>30</iCombatPercent>
			<iCityAttack>0</iCityAttack>
			<iCityDefense>0</iCityDefense>
			<iHillsAttack>0</iHillsAttack>
			<iHillsDefense>0</iHillsDefense>
			<iKamikazePercent>0</iKamikazePercent>
			<iRevoltProtection>0</iRevoltProtection>
			<iCollateralDamageProtection>0</iCollateralDamageProtection>
			<iPillageChange>0</iPillageChange>
			<iUpgradeDiscount>0</iUpgradeDiscount>
			<iExperiencePercent>0</iExperiencePercent>
			<TerrainAttacks/>
			<TerrainDefenses/>
			<FeatureAttacks/>
			<FeatureDefenses/>
			<UnitCombatMods/>
			<DomainMods/>
			<TerrainDoubleMoves/>
			<FeatureDoubleMoves/>
			<UnitCombats>
			</UnitCombats>
			<HotKey/>
			<bAltDown>0</bAltDown>
			<bShiftDown>0</bShiftDown>
			<bCtrlDown>0</bCtrlDown>
			<iHotKeyPriority>0</iHotKeyPriority>
			<Button>,Art/Interface/Buttons/Tech/CloakingDevice.dds</Button>
		</PromotionInfo>

And I added this code to CivMainInterface.py:
Spoiler :
Code:
#added General Quarters buttons
					pUnit = g_pSelectedUnit
					iUnitType = pUnit.getUnitType()
					pUnitOwner = gc.getPlayer( pUnit.getOwner( ))
					pUnitTeam = gc.getTeam(pUnit.getOwner())
					if (pUnitOwner.isTurnActive( ) and pUnit.canMove()):
						if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_RED_ALERT')) and not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ1')) and pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ2')) and pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ3')):
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_GREEN1')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 662, 662, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_YELLOW1')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 663, 663, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_RED1')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 664, 664, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
						if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_RED_ALERT')) pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ1')) and not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ2')) and pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ3')):
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_GREEN2')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 999, 999, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_YELLOW1')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 663, 663, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_RED1')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 664, 664, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
						if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_RED_ALERT')) pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ2')) and not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ1')) and pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ3')):
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_GREEN2')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 662, 662, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_YELLOW2')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 999, 999, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_RED1')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 664, 664, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1	
						if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_RED_ALERT')) pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ3')) and not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ1')) and pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ2')):
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_GREEN2')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 662, 662, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_YELLOW1')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 663, 663, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1
							screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('INTERFACE_RED2')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 999, 999, False )
							screen.show( "BottomButtonContainer" )
							iCount = iCount + 1	
							
#end of general quarters buttons

#ADD General Quarters
		
		#Green Alert
		if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 662 and inputClass.getData2() == 662):
			self.iPushedButtonUnit = g_pSelectedUnit
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ1'), true)
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ2'), false)
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ3'), false)
			g_pSelectedUnit.changeMoves(60)
			CyAudioGame().Play2DSound('AS2D_CLOAK_OFF')
			
		#Yellow Alert
		if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 663 and inputClass.getData2() == 663):
			self.iPushedButtonUnit = g_pSelectedUnit
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ1'), false)
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ2'), true)
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ3'), false)
			g_pSelectedUnit.changeMoves(60)
			CyAudioGame().Play2DSound('AS2D_CLOAK_OFF')
			
		#Red Alert
		if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 664 and inputClass.getData2() == 664):
			self.iPushedButtonUnit = g_pSelectedUnit
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ1'), false)
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ2'), false)
			self.iPushedButtonUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GQ3'), true)
			g_pSelectedUnit.changeMoves(60)
			CyAudioGame().Play2DSound('AS2D_CLOAK_OFF')
			
#end of general quaters
 
So it seems like that code should have worked, but instead I got the "You Have been Defeated" turn 1 bug instead...

It definitely has something to do with the "CivMainInterface.py" file as when I reverted it, it went back to working as it did before. Could someone take a look at the code I posted above and tell me if I did something disastrous??
 
Have not looked at the code, because it'll be easier when we know where the error is.

-> you need to activate Python exceptions, so that you get error messages when something in your code is screwed up.
To activate them, go to your Documents\My Games\Bts\Civilization4.ini, and change
PHP:
; Set to 1 for no python exception popups
HidePythonExceptions = 1

to 0.
Then make your changes again, and start the game. You should get some error popups, if something is wrong. In these popups also the line is mentioned, which causes the problem. Which would be the important part, because it's definitely easier to spot a bug when you know where to look at.
 
hmm... Well that gave me a billion errors and not one of them the slightest bit useful.

The first error I get is "Traceback (most recent call last):" so Maybe it is some sort of syntax problem? It all looks right to me.

I wonder if it has anything to do with my usage of :
Code:
screen.show( "BottomButtonContainer" )
iCount = iCount + 1

I'm not really sure what those do, but I called it every time I added a button.
 
Don't think it's related to that.
And at least one message has to be useful.
You should probably try to add only 1 button at once. If that still doesn't help to identify the error, then take parts of your custom code out, until it works again. And then re-examine the last part which you took out, because there has to be the error.
 
The first error I get is "Traceback (most recent call last):" so Maybe it is some sort of syntax problem? It all looks right to me. Which even happens when I only add one button.

Right now all I have added is:
Code:
if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_RED_ALERT'))):
       screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_GREEN1").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 700, 700, False )
       screen.show( "BottomButtonContainer" )
       iCount = iCount + 1
and even that gives me the error.
 
OK....

The problem seems to be with this line:
Code:
screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_GREEN1").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 700, 700, False )
But I have no idea why.
 
OK....

The problem seems to be with this line:
Code:
screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_GREEN1").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 700, 700, False )
But I have no idea why.

What does the error message say exactly?
 
The error exactly says "Traceback (most recent call last):" and that is is. It is fallowing errors are a bunch of blank error messages and question marks. I'll shoot a video of it if you'd like.
 
Code:
#Added in Cloaking Devices -- TC01 and other buttons
	pUnit = g_pSelectedUnit
	iUnitType = pUnit.getUnitType()
	pUnitOwner = gc.getPlayer( pUnit.getOwner( ))
	pUnitTeam = gc.getTeam(pUnit.getOwner())
	if (pUnitOwner.isTurnActive( ) and pUnit.canMove()):
		if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_CLOAKING_DEVICE')) and not (gc.getUnitInfo(pUnit.getUnitType()).isNoCloaking() or pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK')) or pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_FIRE')))):
			screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('PROMOTION_CLOAK')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 660, 660, False )
			screen.show( "BottomButtonContainer" )
			iCount = iCount + 1
		if (pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK')) or pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CLOAK_FIRE'))):
			screen.appendMultiListButton( "BottomButtonContainer", gc.getPromotionInfo(gc.getInfoTypeForString('PROMOTION_CLOAK')).getButton(), 0, WidgetTypes.WIDGET_GENERAL, 661, 661, False )
			screen.show( "BottomButtonContainer" )
			iCount = iCount + 1
                 [COLOR="Lime"]#this is what I added[/COLOR]
                 if (pUnitTeam.isHasTech(gc.getInfoTypeForString('TECH_RED_ALERT'))):
                       [COLOR="Red"] screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_GREEN1").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 700, 700, False )[/COLOR]
			screen.show( "BottomButtonContainer" )
		        iCount = iCount + 1

#End of butttons

Now if I comment out the line in red I get no errors. But with it in I get this:
Video
 
The error exactly says "Traceback (most recent call last):" and that is is. It is fallowing errors are a bunch of blank error messages and question marks. I'll shoot a video of it if you'd like.

Those are not separate errors, they are all parts of the same error message. Sadly, the pop-ups sometimes report each line of the message in a separate pop-up, or worse.

The entire message should appear in the PythonErr.log file in the game's Logs folder in a more readable form (and you can copy the text into your message here instead of making a video).
 
Back
Top Bottom