Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: [0.95a] small API issue  (Read 745 times)

Mira Lendin

  • Captain
  • ****
  • Posts: 315
    • View Profile
[0.95a] small API issue
« on: August 14, 2021, 06:10:18 AM »

I noticed that if you try to retrieve "ProjectileSpecAPI" from an Instance of "WeaponSpecAPI" via ".getProjectileSpec() function" you get an instance of "com.fs.starfarer.loading.specs.h" instead of "com.fs.starfarer.api.loading.ProjectileSpecAPI", even if you try to cast it via (ProjectileSpecAPI) the game just crashes, from how the functions are worded this has to be an unintended behavior.
« Last Edit: August 14, 2021, 06:12:12 AM by Mira Lendin »
Logged
^^

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: [0.95a] small API issue
« Reply #1 on: August 14, 2021, 08:37:50 AM »

The returned object can implement either MissileSpecAPI or ProjectileSpecAPI. The return type of getProjectileSpec() is "Object" so it can return anything. Worth noting that both MissileSpecAPI and ProjectileSpecAPI are interfaces, so what getProjectileSpec() actually will be some other under-the-hood class that implements one of those two interfaces. You can use the "instanceof" operator to check which one you've got.
Logged

Mira Lendin

  • Captain
  • ****
  • Posts: 315
    • View Profile
Re: [0.95a] small API issue
« Reply #2 on: August 14, 2021, 10:15:56 AM »

The returned object can implement either MissileSpecAPI or ProjectileSpecAPI. The return type of getProjectileSpec() is "Object" so it can return anything. Worth noting that both MissileSpecAPI and ProjectileSpecAPI are interfaces, so what getProjectileSpec() actually will be some other under-the-hood class that implements one of those two interfaces. You can use the "instanceof" operator to check which one you've got.
Ohh i see, been stuck on this point the whole day, thanks a lot for responding!
Logged
^^