Types - finding a particular one

BlitzPlus Forums/BlitzPlus Beginners Area/Types - finding a particular one

Markh999(Posted 2004) [#1]
Suppose I have 30 aliens on the screen - all the same except for their x, y position and they are defined as a type. Is there any way of getting, say, the 17th alien created to drop a bomb (for example) without having to Loop through all those created until a count reaches 17 (using the FOR .... EACH command)

I've tried attaching a number within the Type itself:

Type alien
Field x,y ;The x and y coords
Field count ;alien number
End Type

but can't see how this will help.

Thanks for any help.


CGV(Posted 2004) [#2]
The main drawback of linked lists is the fact that you can't go straight to a particular item but have to iterate through the whole list to find the one you're looking for so I'm afraid you're out of luck.

This article over at blitzcoder, Definitive Guide to Types, may help you with your problem.

Scroll down to the section titled:
Other type commands: 'Insert', 'Before', 'After', 'First', 'Last' and 'Delete'


Grey Alien(Posted 2004) [#3]
Make an array (using Dim)of your types an reference them by an index number (instead of using a loop with Each) as follows:

Don't forget to free them all at the end.

Type TheType
Field A%
Field B$
End Type

MAX_TYPES = 10

Dim Types.TheType(MAX_TYPES)

For i = 0 To MAX_TYPES-1
Types(i) = New TheType
Next

Types(3)\B = "hello"
Notify Types(3)\B


Markh999(Posted 2004) [#4]
Thanks for the reply - can't believe I didn't think of that !! - Thanks very much Mr Alien


Grey Alien(Posted 2004) [#5]
No problemo earthling.