entity exist?

Blitz3D Forums/Blitz3D Beginners Area/entity exist?

Santiworld(Posted 2009) [#1]
how can i return some value if an entity exist or not?

something like

x = entity
if x exist then freeentity (x)


Warner(Posted 2009) [#2]
You could check if it's handle is zero or not. But then, you'll have to reset the handle to zero if you are using FreeEntity.
cube = CreateCube()
if cube = 0 then print "mesh creation failed"
if cube <> 0 then freeentity cube: cube = 0



Santiworld(Posted 2009) [#3]
:) thanks!!


jfk EO-11110(Posted 2009) [#4]
But then there is a problem, because after DeleteEntity it will still be non-zero.

A more reliable solution for EntityExist() is in the code archives, together with the iteation trough all entities. This way you can parse all existing entities, ask if they are a mesh, or a camera etc.

http://www.blitzbasic.com/codearcs/codearcs.php?code=2012


Zethrax(Posted 2009) [#5]
Ideally you should store all the objects that need to be updated on type-lists, and update them from those type-lists. Where it becomes necessary to check if an object has been deleted, just sequence its type-list to see if it is still on that list.

Example:-
(Note that it may be better to use some sort of managed ID values to identify the objects, rather than the entity handle. It's possible that a new entity may get allocated the same handle value as a deleted entity, which could cause an intermitant bug.)
Type T_monster
 Field entity
End Type

; Update all monsters.
For monster.T_monster = Each T_monster
 UpdateMonster( monster\entity )
Next

Function GetMonsterByEntity.T_monster( entity )

; NOTE: Returns a pointer to the monster object if the monster entity exists, or a null pointer if it doesn't exist.

Local monster.T_monster, result.T_monster

For monster = Each T_monster
 If monster\entity = entity then result = monster
Next

Return result

End Function