Jeez...I scoured the folder where all of the help html's are kept, I used the quick help thing, I even downloaded the extra help doumentation! But B3d still can't tell me what Object does! Does anyone know?
Does anyone know what the function 'Object' does?
Blitz3D Forums/Blitz3D Programming/Does anyone know what the function 'Object' does? Object.typename(objecthandle)
typename: the custom type the Object function should return
objecthandle: an integer handle produced by the Handle function
The Object function takes the integer handle of an object and if it exists
returns an actual reference to the object given it is of the Type specified.
Handle(object)
object: an instance of a custom type
The Handle command allows you to retrieve an integer handle for a specific
instance of a custom type.
Because the result is an integer, Handle allows a reference to any type of
object to be stored in a standard integer variable where custom type variables
may only reference objects of a single specified type. This freedom opens the
door for those wishing to implement more abstract functions that can deal
with multiple types of data.
typename: the custom type the Object function should return
objecthandle: an integer handle produced by the Handle function
The Object function takes the integer handle of an object and if it exists
returns an actual reference to the object given it is of the Type specified.
Handle(object)
object: an instance of a custom type
The Handle command allows you to retrieve an integer handle for a specific
instance of a custom type.
Because the result is an integer, Handle allows a reference to any type of
object to be stored in a standard integer variable where custom type variables
may only reference objects of a single specified type. This freedom opens the
door for those wishing to implement more abstract functions that can deal
with multiple types of data.
Yeah, it's a really useful function to enable you to link a mesh object to the instance of the type it refers to -
when you create a mesh, set its name to Handle(Object) of the data type instance that holds it's info -
Then you can link straight back to this type instance later (for example from a picked object or a collision) using the object command -
when you create a mesh, set its name to Handle(Object) of the data type instance that holds it's info -
MyObject.TYPE_object = New TYPE_object NameEntity MyMesh , Handle(MyObject)
Then you can link straight back to this type instance later (for example from a picked object or a collision) using the object command -
entity = CameraPick( camera , MouseX() , MouseY() ) if entity foundobject.TYPE_object = Object.TYPE_Object( EntityName(entity) ) endif
Ulitmately, Blitz Object/Handle commands provide random access to custom type object's info. All other commands: For...Each, First, After, Before, Last provide sequential access.
You can also use a Array of Custom Types for random access. You have to create your own ID management. I personally use FILO Stack or a basic incremental Counter. An Array of Types is useful when when more control over the assignment ID.
Type Setup
Type Creation
Using the Type
Yes, there is slightly more work that goes into using array of custom types, but, if you desire more control over the management of object IDs they do trick.
You can also use a Array of Custom Types for random access. You have to create your own ID management. I personally use FILO Stack or a basic incremental Counter. An Array of Types is useful when when more control over the assignment ID.
Type Setup
Type TYPE_object Field ID%; required field, useful for reverse reference. End Type Const TYPEOBJECT_MAX%=255; maximum number of objects Dim TYPE_object _Handle.TYPE_object(TYPEOBJECT_MAX%) ;Custom Type Array Global TYPE_object _Handles; ID counter
Type Creation
Function TYPE_objectCreate%() ;Purpose: Return the ID of the newly created object. If TYPE_object _Handles<TYPEOBJECT_MAX% this.TYPE_object = New TYPE_object TYPE_object _Handles = TYPE_object _Handles + 1 ;increment the ID counter this\ID% = TYPE_object _Handles TYPE_object _Handle(this\ID%)=this Return this\ID% End If End Function
Using the Type
MyObject=TYPE_objectCreate() NameEntity MyMesh ,MyObject entity = CameraPick( camera , MouseX() , MouseY() ) if entity foundobject.TYPE_object = TYPE_object _Handle(EntityName(entity)) endif
Yes, there is slightly more work that goes into using array of custom types, but, if you desire more control over the management of object IDs they do trick.
Interesting. Does that example overcome the memory leaking problems of Object/Handle?
memory leaking problems? just becuase this is probably my only chance to find this out, could someone explain this issue with Object/Handle to me