PYTHON CODE help required - Air vs Naval

No, you don't understand what I mean by the exceptions. If you insert code that isn't perfectly logical (to the computer) it will throw an exception. This messes your game up, so you need to get to the bottom of it.

Also, note my second post above. It might be that you simply didn't use all of the code... Could you post the entire onCombatResult() method from your Event Manager? It shouldn't be hard to spot the problem. With any luck.
 
No, you don't understand what I mean by the exceptions. If you insert code that isn't perfectly logical (to the computer) it will throw an exception. This messes your game up, so you need to get to the bottom of it.

Also, note my second post above. It might be that you simply didn't use all of the code... Could you post the entire onCombatResult() method from your Event Manager? It shouldn't be hard to spot the problem. With any luck.

Here it is...
Spoiler :
def onCombatResult(self, argsList):
'Combat Result'
pWinner,pLoser = argsList
playerX = PyPlayer(pWinner.getOwner())
unitX = PyInfo.UnitInfo(pWinner.getUnitType())
playerY = PyPlayer(pLoser.getOwner())
unitY = PyInfo.UnitInfo(pLoser.getUnitType())
## mechaerik War Prize ModComp START##
pPlayer = gc.getPlayer(pWinner.getOwner())
if not (gc.getPlayer(pWinner.getOwner()).isBarbarian()):
if (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NAVAL")) or (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_MELEE")) or (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_GUN")) or (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_ARCHER")):
if (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NAVAL")) or (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_ARCHER")) or (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_GUN")) or (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_MELEE")) or (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_SIEGE")):
if not (unitY.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_PRIVATEER")):
if not (unitY.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_PRIVATEER")):
if CyGame().getSorenRandNum(100, "Bob") <= 25:
iUnit = pLoser.getUnitType()
newUnit = pPlayer.initUnit(pLoser.getUnitType(), pWinner.getX(), pWinner.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
newUnit.finishMoves()
newUnit.setDamage(50, pWinner.getOwner())
## War Prize Modcomp END##
## Air Versus Naval START##
if (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NAVAL")) :
if (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_AIR")) :
if CyGame().getSorenRandNum(100, "Bob") <= 50:
pLoser.setDamage(100, pPlayer)
## Air Versus Naval END ##
if (not self.__LOG_COMBAT):
return
if playerX and playerX and unitX and playerY:
CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s'
%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(),
playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))

def onCombatLogCalc(self, argsList):
'Combat Result'
genericArgs = argsList[0][0]
cdAttacker = genericArgs[0]
cdDefender = genericArgs[1]
iCombatOdds = genericArgs[2]
CvUtil.combatMessageBuilder(cdAttacker, cdDefender, iCombatOdds)


Once again thx to try to help...
 
Firstly, use code tags when you post code. Otherwise the indentation isn't showing.

Secondly, you messed up the indentation. While the present code uses tabs for indentation, the new code you added uses blank spaces. You can't mitch-match white space!
 
You also missed a couple of other things. This is probably what you need:
Code:
## Air Versus Naval START##
		if (unitX.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_NAVAL")) :
			if (unitY.getUnitCombatType() == gc.getInfoTypeForString("UNITCOMBAT_AIR")) :
				if CyGame().getSorenRandNum(100, "Bob") [COLOR="Red"]<[/COLOR] 50:
					pLoser.setDamage(100, pPlayer[COLOR="Red"].getID()[/COLOR])
## Air Versus Naval END ##                
		if (not self.__LOG_COMBAT):
I converted the blank spaces into tabs for above lines and made the marked changes to the code.
 
Firstly, use code tags when you post code. Otherwise the indentation isn't showing.

Secondly, you messed up the indentation. While the present code uses tabs for indentation, the new code you added uses blank spaces. You can't mitch-match white space!

AAA thx guys... thx....
 
...and how to fix it:
Download a version of python from here, and look at the code with idle.
It should then somehow look like the code kiwitt showed us, with the same indentation.
No, the important thing isn't how it looks. SIMPA need to understand how to work with indentation. (I think I'll just fetch my indentation tutorial... Right back.)
 
SIMPA: We're here to help, so feel free to post anything you need help with.

This is what I wrote about indentation awhile ago. It should explain the what, why and how.
 
You're most welcome. :goodjob:
 
Thanks for the fixes. I will adjust accordingly.
 
Back
Top Bottom