indexing types

Blitz3D Forums/Blitz3D Programming/indexing types

is there a way, instead of first last after etc to index a type using a number. rather than using for next to search an index field

rather than :
for b.bollocks.each bollocks
if b\index=20 exit
next

is there something like :
b.bollocks=bollocks(20)

No, sorry.

But you can use a mixed way to store your info, using array of types - that is, each array item refers to a type element, so you could then do something like:

print array_of_bollocks(20)\score


Sergio.

thought as much

thanks.

Using Object and Handle, you can get the handle for the type:

;Simple type
Type Test
	Field A%
	Field B#
End Type

;Create a new type instance of Test, named T
T.Test = New Test

;Fill the fields
T\A% = 10
T\B# = 52.25

;Get the handle
TypeHandle% = Handle(T.Test)

;Convert handle to type using Object
U.Test = Object.Test(TypeHandle%)

;Print the field
Print U\A%

;If we change the original types fields, we see that they both use the same fields, even though
;they're named differently (T.Test and U.Test). So, both instances point to the exact same type,
;although they're named differently.

;Set T\A% to 20
T\A% = 20
;Print U\A%  (should show 20)
Print U\A%

WaitKey


It's a shame with types that there isn't 'proper' database indexing, that way you could do something like:
type bollock
field id
field size
indexon id
end type

find bollock where bollock.id=5


thanks guys, mabe if we smile at mr sibly he can write in a

b.boobs=indexed boobs[10]

:)

What!!! of course you can do that!!

MaxBoobs = 20

Type boobs
field Size
field id
end type

Dim BoobList.boobs(MaxBoobs)

for B = 1 to MaxBoobs
booblist(B) = new boobs
booblist(B)\Size = B * 10
booblist(B)\id = B ;not needed, but handy
next

;Usage

Index = 5
MyBoobs.boobs = booblist(Index)
print MyBoobs\Size
pring MyBoobs\ID