Handle and Objetc

Blitz3D Forums/Blitz3D Programming/Handle and Objetc

Yue(Posted 2016) [#1]
Someone help me understand podira these two commands in a simple way please.


Matty(Posted 2016) [#2]
Object and Handle allow you to get a specific instance of a type by using an integer.

Much the same way that other entities, images, sounds etc are referred to using an integer handle you can store an integer value as the 'handle' to a type and then get it using the object command as shown below.

Type mytype

Field x,y,z

End Type

a.mytype = New mytype
a\x = 1
a\y = 2
a\z = 3

b.mytype = New mytype
b\x = 4
b\y = 5
b\z = 6

myinteger = Handle(b)

c.mytype = Object.mytype(myinteger)
Print c\x + " " +c\y + " " + c\z
;should display '4 5 6'
WaitKey
End




Yue(Posted 2016) [#3]
Thank you, and as it relates to NameEntity?


_PJ_(Posted 2016) [#4]
Neither Object nor Handlre relate to NameEntity

NameEntity entity,Name$
Just assigns that string to the entity for easier identification.
FindChild(Parent,Name$) makes use of the "name" string

It can however be useful in certain circumstances to use the EntityName to store the Str(Handle()) as an EntityName so as to determine the TYPE INSTANCE to which an entity 'belongs'
Personally, I find this very useful in collisions for example:

Type MYTYPE
Field Entity
End Type

T.MYTYPE=New MYTYPE
T\Entity=CreateCube()
NameEntity(T\Entity,Handle(T))


This way, if, for example, an entity in the collision list (B3D's collision system) is returned, it is possible to use T.MYTYPE=OBJECT.MYTYPE(EntityName(CollisionEntity)) to retrieve the overarching Type Instance.


Yue(Posted 2016) [#5]
@_PJ_ Thanks You. :)


The data on EntityName took me out of trouble.