Jump to content

BUG? Airbase.getCategory() does not give correct value against Airbase.Category.SHIP


Recommended Posts

Posted

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?

Posted

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.

Posted (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 by Chump
Clarification
  • Thanks 1
Posted

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

Posted
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?

Posted (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 by Chump
  • Thanks 1
Posted
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...

Posted
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. 

  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

  • Recently Browsing   0 members

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