Any way to detect wether a table is a display object?

?

Could you check whether the .x value is nil, if not it must be a display object?

There are several ways to go about this.

Here is one way, that would only apply to display objects (not display groups, if you wanted to filter)

local isDisplayObject = type( myDisplayObject.setFillColor ) == "function"

If you just want to know if something is a display object (including groups)

local isDisplayObject = type( myDisplayObject.removeSelf ) == "function" 

ahh thank you Gremlin, solved :smiley:

No worries :wink:

same thing -

if( object.removeSelf ~= nil ) then

 …

If the object is on the display, it has the display member functions still attached (insert, remove, etc).

If the object has been removed() from the display, no functions are hanging there (and the item is nerfed as well, it can’t be re-inserted or used again I believe).

It is yeah, it just depends on whether he was looking to differentiate a display object to a display group object, if so that wouldn’t give the needed info.

You could also check for differences between a display object and a display group by doing:

if type( object.removeSelf ) == "function" then if type( object.numChildren ) == "number" then -- this is a display group else -- it's a display object end end

Begs the question, is this a good idea ?

yeah, a while ago i made a game where the user builds a little city and then defends it from aliens. All code was contained within a single table, i looped through the table at the end of each phase destroying all gameobjects and nilling out the rest of the variables.

Could you check whether the .x value is nil, if not it must be a display object?

There are several ways to go about this.

Here is one way, that would only apply to display objects (not display groups, if you wanted to filter)

local isDisplayObject = type( myDisplayObject.setFillColor ) == "function"

If you just want to know if something is a display object (including groups)

local isDisplayObject = type( myDisplayObject.removeSelf ) == "function" 

ahh thank you Gremlin, solved :smiley:

No worries :wink:

same thing -

if( object.removeSelf ~= nil ) then

 …

If the object is on the display, it has the display member functions still attached (insert, remove, etc).

If the object has been removed() from the display, no functions are hanging there (and the item is nerfed as well, it can’t be re-inserted or used again I believe).

It is yeah, it just depends on whether he was looking to differentiate a display object to a display group object, if so that wouldn’t give the needed info.

You could also check for differences between a display object and a display group by doing:

if type( object.removeSelf ) == "function" then if type( object.numChildren ) == "number" then -- this is a display group else -- it's a display object end end

Begs the question, is this a good idea ?

yeah, a while ago i made a game where the user builds a little city and then defends it from aliens. All code was contained within a single table, i looped through the table at the end of each phase destroying all gameobjects and nilling out the rest of the variables.