Glloq Posted November 19, 2023 Posted November 19, 2023 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 cfrag Posted November 20, 2023 Solution Posted November 20, 2023 (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 November 20, 2023 by cfrag 2
Glloq Posted November 21, 2023 Author Posted November 21, 2023 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 ^^
609_Relentov Posted November 26, 2023 Posted November 26, 2023 Thanks cfrag! This bug fix broke one of my scripts, so thanks for the suggestion to use Object.getCategory(event.initiator)...
Recommended Posts