Jump to content

Event Birth - event.initiator:getCategory() always return 0 - How to find my object category?


Go to solution Solved by cfrag,

Recommended Posts

Posted

Hello everyone,

In my mission, I used to monitor what kind of object launch an event like the event birth to do specific stuff if it is a unit, a scenery or a static object. Unfortunately since a few days (can't say if it's from the last patch or the previous one) event.initiator:getCategory() always return 0

Did something change? I guess i can still find if it's a unit, a static or a scenery by using Unit.getByName (almost same thing for static or scenery) with event.initiator:getName() if I have no other choice but I would rather find this using my event.initiator .

What should I do to find my object category?

 

Sincerely

 

  • Solution
Posted (edited)

Short answer: It was changed a few days ago. 

use Object.getCategory(event.initiator) 

 

Long answer

When you invoke event.initiator:getCategory() you should have always received the result of UNIT.getCategory, WEAPON.getCategory, STATICOBJECT.getCategory, etc's invocation - if Lua was a true OOP language, that is, because that is how inheritance is supposed to work. For years, however, this was implemented wrong, and getCategory was not inherited, always invoking the class's root method Object.getCategory

This was changed a few days ago in the second release of 2.9 beta, after years, and quite abruptly; it was mentioned in passing in the release notes. Since this was a long-standing bug, there are now many scripts that rely on the bug to not be fixed, and now break after the bug has been corrected. Many popular libraries need some tweaking because the bug was now being accepted as 'canon'.

Remedy: Since you are interested in the root class invocation of the Object tree, the solution is to explicitly invoke the root class:

Object.getCategory(event.initiator)

Edited by cfrag
  • Like 2
Posted

Thanks a lot, this works!

I may have missed this in the release notes. It's been there for such a long time that I thought it was a feature not a bug ^^

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...