Total number of entitys

Blitz3D Forums/Blitz3D Beginners Area/Total number of entitys

Chimeara(Posted 2004) [#1]
Is their a cimand that returns the total number of entity's or/and what they are? mabey something to do with picking?


Zethrax(Posted 2004) [#2]
There's no command to return the total number of entities, as far as I know. You need to use a global variable as a counter and update it as you create or delete them, if you want to do this.

The best way (in my opinion at least) to identify what an entity is, is to store that information in a Blitz Type structure and use the undocumented command, 'Handle()' along with the 'NameEntity' command to store a pointer to that Type element in the entity's namestring. Use the undocumented command, 'Object()', along with the 'EntityName$()' command to retrieve the Type pointer. The advantage of this is that you can store a lot of additional information in the entity's Type element. If you only need to store a small amount of info then you can store it directly in the entity's namestring, of course.

eg.

Type ENTITY_DATA_STRUCT
Field entity_name$
Field entity_type_id
Field entity_class_id
End Type

Global entity_data.ENTITY_DATA_STRUCT = New ENTITY_DATA_STRUCT

Global entity_handle = CreatePivot () ; Create a bare entity.

; Store Type pointer in entity's namestring.
NameEntity entity_handle, Handle ( entity_data )

; Retrieve Type pointer from entity's namestring. Note that the 'Object' command needs to be followed by the identifier of the Type structure to be output, with a dot as a separator.
entity_data = Object.ENTITY_DATA_STRUCT( EntityName$ ( entity_handle ) )


jhocking(Posted 2004) [#3]
To elaborate a little on his suggestion of using types to store all entities, if you do that you can easily count how many entities are in the scene by using For/Next/Each to loop through all the type instances, incrementing a counter as you go.


StOrM3(Posted 2004) [#4]
If I am correct, the code above would then allow you to use entity_data\entity_type_id etc.. meaning using the Object.Entity_Data_Struct(EntityName$(entity_handle)) you could then assign this to a temp variable and use this temp variable to access the fields of the type correct ?

This sounds like what I was needing in my question.. about using hideentity on a temp variable, and accessing the points of entity handle returned from entitycollided etc..

Thank you very very much. Please tell me I'm right.


Zethrax(Posted 2004) [#5]
StOrM3, it sounds like what you're suggesting is correct.