Code archives/Algorithms/Object and Handle with Entities

This code has been declared by its author to be Public Domain code.

Download source code

Object and Handle with Entities by Rob2003
Example on how to use object and handle to hold unlimited data about entities with very low lookup time.
; Example on how to use object and handle
; to hold unlimited data about entities with
; very low lookup time.
; By Rob Cummings

Graphics3D 640,480,0,2

Type info
	Field name$,a,b,c,stuff,mass#,physics,etc
End Type

;create a ball and some related information.
a.info=New info
a\name$="bowling ball"
a\mass#=0.9
ball=CreateSphere()
NameEntity ball,Handle(a) ; the type handle held within the entity name.


;now all you do is grab the entity using any of Blitz's own commands.
;This could be LinePicks, Collisions And so forth.


;uncomment for a proper example within a collision framework
;ent = EntityCollided(bat,collisiontype_ball)
ent=ball ; test

If ent
	a.info = Object.info(EntityName(ent)) ; quickly retrieve source type
	Print a\name$
	Print a\mass#
EndIf

Comments

Techlord2004
Another option is to use a Array of Types. Ideal for managing types with a specified collection amount and provides faster access than using Object/Handle.




Dabbede2004
I prefer the 1st solution! Great!


Mikorians2013
Techlord's 2nd infohandle solution didn't work out and always
Retrieves type 2.
Are we supposed to iterate through each infohandle?
Could you finish your line of thought please?
Basically- Ent had no connection to infohandle at the end of the program.


Code Archives Forum