Jump to content

Hitting the airfield fence in Beirut airport gives script error


Terzi

Recommended Posts

------------------------

if event.id == world.event.S_EVENT_DEAD or event.id == world.event.S_EVENT_CRASH then

....

elseif event.initiator:getCoalition()==1 then

-------------------------

 

The script above is to detect destroy events, but the fences are also objects that get also destroyed. So;

 

Although the airfield belongs to Blue coalition, killing the fence, when getCoalition is called, makes an error thrown.

 

See images for error window and mission result.

 

I find no way to aviod this, if it happens. There must be way to avoid "getCoalition" returning nil.

err.png

err2.png


Edited by Terzi
typo

[CENTER]

Signum_Signatur.png

[/CENTER]

Link to comment
Share on other sites

26 minutes ago, Veteran66 said:

Look here on my last post

 

This is somewhat similar thing, but not the solution to this problem. I think the object's getCoalition should never ever return a nil. If this airfield belongs to a coalition then it should be 0, 1 or 2.

[CENTER]

Signum_Signatur.png

[/CENTER]

Link to comment
Share on other sites

That isn't a bug and is something you have to code around. Scenery objects simply do not belong to a coalition. This is the same for some fence around an airbase and some fence in the middle of nowhere that got destroyed due to a falling air to air missile. The class hierarchy is basically: 

 

Object>Scenery

Object>Coalition>Unit, Weapon, Airbase, StaticObject 

 

So they all inherit the object class, but weapons, units, airbase, etc also inherit the coalition class. While scenery objects just inherit the object class. 

 

Should be able to check event.initiator:getCategory() to filter out Scenery objects and everything else. 

 

 

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

Link to comment
Share on other sites

28 minutes ago, Grimes said:

Should be able to check event.initiator:getCategory() to filter out Scenery objects and everything else. 

 

 

Thanks for your help! But getCategory() always returns helicopter. As your previous advice that I found here, I check the getDesc(). But still even if the hierarchy is as you described, they should be constructed with neutral coalition, or getCoalition() method level should be lowered to derived classes.

[CENTER]

Signum_Signatur.png

[/CENTER]

Link to comment
Share on other sites

The fun and annoying thing about a function like getCategory() is it should be conditional on where and how it is called. The annoying thing is it is bugged at the moment. At least it is bugged so it is still useful. Let me explain. 

 

Object.getCategory() would return the main architype for a given object. So the following values would correspond with each other. 

  UNIT    1
  WEAPON  2
  STATIC  3
  BASE    4
  SCENERY 5
  Cargo   6

Unit.getCategory() would return the type of unit. 

  AIRPLANE      = 0,
  HELICOPTER    = 1,
  GROUND_UNIT   = 2,
  SHIP          = 3,
  STRUCTURE     = 4

 

Airbase.getCategory() would return the category of airbases. 

  AIRDROME = 0,
  HELIPAD = 1, 
  SHIP = 2,

 

In practice it could look something like this: 

local cv = Unit.getByName("Stannis")
Object.getCategory(cv) -- 1
Unit.getCategory(cv) -- 3
Airbase.getCategory(cv) -- 2

 

However in practice as stated above that aspect of it is annoyingly bugged. Only the Object.getCategory() works correctly. For the others you have to use getDesc() and check the category in there. 

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

Link to comment
Share on other sites

  • Recently Browsing   0 members

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