Manipulating a newly created unit

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I have a plot with 4 units that are all the same exact type. Let's say I create a new unit (a 5th unit) that is also the same type. What I want to do is to isolate the new unit after it is created so that I can manipulate it (give it a promotion, change an attribute, etc.), as opposed to the other 4 units. Will the following line of code work to create and isolate a new unit?

Code:
playerNewUnit = pPlayer.initUnit(iUnitType, iX, iY, DefaultUnitAI, DirectionTypes.NO_DIRECTION)

Using this line, can I use the pLayerNewUnit to do the following:

Code:
pLayerNewUnit.setHasPromotion(iProm)


I don't want the promotion line to create a sixth unit, rather I want it to promote the unit just created. Will it work?
 
Because, if you look the CyPlayer.initUnit() up in the API, the method returns a CyUnit instance. This took awhile for me to realize also.

Most methods that do something are labeled VOID, meaning that they return a default None but instead do some other interesting things. But some return instances of classes, like initUnit().
 
Back
Top Bottom