onUnitPromoted not working?

Kael

Deity
Joined
May 6, 2002
Messages
17,403
Location
Paris, France
Anyone able to get the onUnitPromoted function to work? I assumed it would kick whenever you select a promotion for a unit (when it levels up) but no matter what code I add to the function it doesn't have any effect.
 
Yes. I'm pretty sure it runs the code when the unit get's promoted (rather then when the unit gets leveled up)

Where are you adding the code? You should be doing it in CvEventsManager... or a file which substitues for the EventsManage (importing it).
 
The Great Apple said:
Yes. I'm pretty sure it runs the code when the unit get's promoted (rather then when the unit gets leveled up)

Where are you adding the code? You should be doing it in CvEventsManager... or a file which substitues for the EventsManage (importing it).

I tried it through the nice ways but since I thought maybe I was doing something wrong I went ahead and made changes directly to the functions in the main python cvEventManager.py file just to make sure it was inheriting my changes correctly. Still nothing.
 
Nope, it doesn't ever fire. I've debugged it with some debug output tools and nothing I do gets the event to fire at all.
 
Really?

I'm sure I got it to work before...

*looks around for script which it worked on*

Right... can't find one. I'll believe you. That's quite a pain really.
 
Yeah, I had big plans for that function.
 
Kael said:
Yeah, I had big plans for that function.
Hmm - it is possable to bodge up a fuction similar to it which triggers before you give it the promotion, instead of after - if that will suffice?
 
The Great Apple said:
Hmm - it is possable to bodge up a fuction similar to it which triggers before you give it the promotion, instead of after - if that will suffice?

That won't work for mine, unfortunately :sad: My Hero Unit system changes the base unit based on what promotions a unit takes. Bob the Warrior would become Bob the Swordsman if he took the "Sword Training" promotion or Bob the Spearman if he took the "Big Pointy Stick" promotion, etc.

There's probably still ways I could fudge it - checking all of a player's units at the end of each turn to see if any should level up, for example - but they're a lot more complex and resource or time intensive than the event should be.
 
Hmmm. Ok. So I didn't REALLY believe you.

I checked. It works absoluetely fine. No problems at all.

I think I might be able to guess what was going wrong. In the events manager the are the lines:
Code:
		if (not self.__LOG_UNITPROMOTED):
			return
Now I'm not entirely sure what this does - but "return" means that it won't carry on executing the code. If your code was after this line then it might not have worked.

I can send you a test mod I threw together to check it if you really like - but I can assure you that it works.
 
Back
Top Bottom