How to give Free Promotions to units?

Joined
Feb 6, 2006
Messages
796
There are some events that give a free promotion to every unit of a certain class or combat type (axemen, melee, etc), both existing and future.

In Python, I can easily give a promotion to every existing unit.
However, to also affect the future units, I think I have to use some more code.
I've found those methods in the class CvPlayer: isFreePromotion and setFreePromotion, that seem to do exactly what I want.

I haven't found any occurence of those methods in the Python scripts of BTS, so I'm not sure about how those methods must be used.
Here is the problem: they just don't work!

Some code that I've used, as example:

player = gc.getPlayer(iPlayer)
sName = player.getCivilizationAdjective(0)


This works!

if unit.getUnitCombatType() == unitCombatNaval:
unit.setHasPromotion(promotionFlanking,true)


This works!

bIsFreeProm = player.isFreePromotion(unitCombatNaval,promotionFlanking)

This doesn't work! Execution stops at this line, and an error occurs.
Can anyone help me?
 
It would be helpful if you could post what the error is. I assume the extra space in "promotionFl anking" is a cut and paste error.

I am not an expert, but I believe that isFreePromotion does something different. The "is" functions ask a question. They do not set anything. I think you would use this to find out if a certain player has some other ability resulting in a free promotion, like the protective trait yields free Drill I.

I think you probably want the onUnitCreated method. I haven't used that one yet, but I imagine if you override that and check if the player is the one you want, you could give the promotion to the unit.
 
"promotionFl anking".... of course, a display error! In my code, it's written properly.

"isFreePromotion" is a check function, I've used it only for testing my code, because I'm having the same problem with the setFreePromotion function, which would give the unit a new promotion. I suppose that, if I can make one function work, the other one will work as well.

About the error, both functions don't give particular messages or behaviours.
Because I don't have development environments, my only one debug tool is the messaging system of the game. I insert some AddImmediateMessage instructions where I need them. If those points of the function are reached, a message is showed in the game.
I've seen that, if I put an AddImmediateMessage before and after the setFreePromotion (or the isFreePromotion), the first message is showed, but not the second one.
 
It does not sound like you have turned on python exception logging. It is almost impossible to debug python problems without this. Please see this post for more information.
 
Back
Top Bottom