TEMPEST.114 Posted October 15, 2022 Posted October 15, 2022 So I'm doing this: if Airbase.getCategory(airbase) == Airbase.Category.SHIP Where 'airbase' is an object returned from: coalition.getAirbases(coalitionID) The airbase is correctly reporting as the carrier Harry Truman. However when I do the first test = to see if it's a ship or if it's an airfield, it fails that test. It seems that the ship's getCategory returns a value of 1, but the AirbaseCategory.SHIP is value 2 Am I using this incorrectly or is there a bug?
toutenglisse Posted October 15, 2022 Posted October 15, 2022 5 hours ago, Elphaba said: ...Am I using this incorrectly or is there a bug? Airbase:getDesc()["category"] == number is reliable.
TEMPEST.114 Posted October 15, 2022 Author Posted October 15, 2022 Hi. That works, in as far as it's returning a number (but then so does my version of the command). The problem is that it's returning a number of 1, but the enum for SHIP is 2. I can force it to work by removing the enum and just putting == 1 but that kinda seems broken.
toutenglisse Posted October 15, 2022 Posted October 15, 2022 1 hour ago, Elphaba said: ...The problem is that it's returning a number of 1... No, on my side :getDesc()["category"] returns 2 for a ship (aircraft carrier of destroyer with helipad) like it should.
Chump Posted October 15, 2022 Posted October 15, 2022 (edited) Doing a quick test with the Harry Truman, I found the following: airbase:getDesc().category -- returns 2 (Airbase.Category.SHIP) airbase:getCategory() -- returns 1 (Object.Category.UNIT) Edited October 15, 2022 by Chump Clarification 1
TEMPEST.114 Posted October 15, 2022 Author Posted October 15, 2022 Thank you @Chump! You’ve found the bug and solved the problem! Amazing!
Chump Posted October 16, 2022 Posted October 16, 2022 The issue is that Airbase does not have a getCategory() function. It extends Object, which does. The Airbase.Category enum is only used for the Airbase.Desc struct. FYI
TEMPEST.114 Posted October 16, 2022 Author Posted October 16, 2022 3 hours ago, Chump said: The issue is that Airbase does not have a getCategory() function. It extends Object, which does. The Airbase.Category enum is only used for the Airbase.Desc struct. FYI Hey @Chump So I'm VERY new to all this and this is only the second script I've ever written on my own, but if something 'extends' it, from what I've read it's supposed to support it but return values that are specific to itself and not the parent. i.e. if Airbase inherits from Object, then it can do everything Object can do but when you use those functions/methods, it should return data that's Airbase specific and not Object specific because, it's an Airbase not a generic. So if this is true, then getCategory SHOULD work the same way, no?
Chump Posted October 16, 2022 Posted October 16, 2022 (edited) @Elphaba getCategory() isn't overridden for Airbase, so it uses the base class (Object) function in this case. Here is what you get when using getCategory(): object:getCategory() returns Object.Category group:getCategory() returns Group.Category spot:getCategory() returns Spot.Category For other classes, you need to access it's Desc struct: unit:getDesc().category returns Unit.Category airbase:getDesc().category returns Airbase.Category weapon:getDesc().category returns Weapon.Category Edited October 16, 2022 by Chump 1
TEMPEST.114 Posted October 16, 2022 Author Posted October 16, 2022 28 minutes ago, Chump said: @Elphaba getCategory() isn't overridden for Airbase, so it uses the base class (Object) function in this case. Here is what you get when using getCategory(): object:getCategory() returns Object.Category group:getCategory() returns Group.Category spot:getCategory() returns Spot.Category For other classes, you need to access it's Desc struct: unit:getDesc().category returns Unit.Category airbase:getDesc().category returns Airbase.Category weapon:getDesc().category returns Weapon.Category Thank you @Chump Where in the documentation could I have worked this out for myself? Or have you looked in the code somewhere to check this out? I want to learn and not make mistakes like this that take me hours to figure out but this does seem odd - some you can use the base method, others you can't. This doesn't seem clear or intuitive...
Chump Posted October 16, 2022 Posted October 16, 2022 @Elphaba Hoggit is probably the best place for official documentation. Although the search feature is handy (and more up-to-date), sometimes you will need to refer to the original documentation: Part 1 Part 2 1
Grimes Posted October 16, 2022 Posted October 16, 2022 17 hours ago, Chump said: The issue is that Airbase does not have a getCategory() function. It extends Object, which does. The Airbase.Category enum is only used for the Airbase.Desc struct. FYI Yes and no. getCategory for objects like weapons and airbases are supposed to have their own copy of sorts of the function that returns the relative category value. IIRC depending on what you wanted there was a difference from running Airbase.getCategory(base) and base:getCategory(). The former would have returned the airbase category while the latter probably would have been the object. The getCategory bug always returning the object category cropped up in 2017 and hasn't been fixed. 1 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Recommended Posts