Problems with Accessing Types

Blitz3D Forums/Blitz3D Beginners Area/Problems with Accessing Types

Doktor Zeus(Posted 2007) [#1]
I'm writing a simple-ish artillery game that uses multiple-stage weaponry. To do this I have to create a list of weapon templates that the program can refer to as it parses through its list of different missiles currently on-screen. A weapon can have any number of stages from one upwards, and so I wanted to use Types to record these with separate arrays containing other weapon information that isn't related to what goes on within each stage, but with pointers to the parts of the stage list to show where a weapon of that type begins and where it should end. Is there a way I can single out individual pointers and store them in the array list so that I can pull out these references quickly, rather than having to always start at the beginning and parse through the whole list of stages to get to the one I want? I think there should be, but I'm having difficulty working out quite how.


DGuy(Posted 2007) [#2]
Do a search for 'Handle' and 'Object'.

These are two undocumented functions that have been OK'd for use (I thought I read somewhere that they HAD been officially documented ...)

'Handle' allows you to get a handle to an already created object. This object-handle can be stored in an array, passed around to functions, etc.. It's just a simple integer.

'Object' allows you to get a 'pointer' back to the original object. The same type of pointer 'new', 'first', 'next' or 'last' would return.

Example 1:
Type MyType_t
 Field Foo%
End Type

local ptr0.MyType_t = new MyType_t
ptr0\Foo = 99
'ptr0' can be used to access the types fields, but 'ptr0' cannot be stored in an array or passed to other functions.


Example 2:
Type MyType_t
 Field Foo%
End Type

local ptr0.MyType_t = new MyType_t
ptr0\Foo = 99
local hobj% = Handle(ptr0) ;; 'hobj' would equal '0' were 'ptr0' not a valid pointer
'hobj' cannot be used to access the types fields, but 'hobj' can be stored in an array and passed to other functions.


Example 3:
Type MyType_t
 Field Foo%
End Type

local ptr0.MyType_t = new MyType_t
ptr0\Foo = 99
local hobj% = Handle(ptr0)
local ptr1.MyType_t = Object(hobj).MyType_t ;; 'ptr1' would equal NULL were 'hobj' not a handle to an object of type 'MyType_t'
ptr1\Foo = 111
'ptr0' and 'ptr1' now refer to the same object. I.E. 'ptr0\Foo' and 'ptr1\Foo' both equal '111'

HTH