Object / Handle

Blitz3D Forums/Blitz3D Programming/Object / Handle

Yue(Posted 2015) [#1]
Whenever I have something to learn, in this case understand that the keyword Handle keeps a indixe according to the created object (if it is not that way correct please), but do not understand the "Objetc", what does to receive the handle, what does?

Type MY_TYPE
	Field whatever
End Type

Global a_custom_type.MY_TYPE = New MY_TYPE ; This could also be a local type pointer.

integer_variable% = Handle( a_custom_type.MY_TYPE )

Print integer_variable%

a_custom_type.MY_TYPE = Object.MY_TYPE( integer_variable% )

Print a_custom_type.MY_TYPE\whatever

WaitKey()




RemiD(Posted 2015) [#2]
the command Handle(instance of a type) allows you to get the reference of this instance of a "Type"

the command Object.Type(reference) allows you to access directly the instance of a "Type" having this reference (some people also call this reference, an "handle", an "id") without using a for next loop

You usually store the reference of the instance in the name of an entity (collidable, pickable) of this instance with NameEntity()
NameEntity(i\Entity,Handle(i))

After a collision or a linepick, you can get the name of a collided/picked entity with EntityName()
reference% = Int(EntityName(Entity))
then you can directly access and then read/write/modify this instance of a Type
i.Type = Object.Type(reference)
i\life# = i\life - 1

See this code example :
http://www.blitzbasic.com/codearcs/codearcs.php?code=3095


virtlands(Posted 2015) [#3]
; If you let the concept evolve, eventually you can use the OBJECT and HANDLE
; commands to create abstract data types.
; Sorry I don't really have any great examples yet....

For z=1 To 20
this = Object.path(z)
If this = Null Then Exit
Print" object("+z+") :: "+pathname$(this)
Next

Type CustomFolder
; place various fields here.
; ...
Field self ; store a copy of its own handle
End Type