How do I create multiple of the same type?

Blitz3D Forums/Blitz3D Beginners Area/How do I create multiple of the same type?

using C you could create multiple of the same structs in this manner:

struct data
{
int x, y;
};
typedef struct data data;

data ship[10]

and use them in a for loop like this:

int i;
for (i = 0; i < 10; i++)
{
ship[i].x = 1;
ship[i].y = 1;
}

Is there a way to create multiple types and use them in a for loop in Blitz3D just like I used in the example code for a C program?

Type dataT        ; 'data' is a reserved word.
  Field x%, y%
End Type

Dim ship.dataT(9) ; 0 to 9, inclusive in blitz.

For i = 0 To 9
  ship(i) = New dataT
  ship(i)\x = 1
  ship(i)\y = 1
Next


oh, I see thank you big10p.

While the code big10p gave you is, as you asked, exactly like the C source, we should probably mention that you can iterate through automatically generated lists of type instances also (which basically cuts out having to use fixed size arrays):
Type dataT        ; 'data' is a reserved word.
  Field x%, y%
End Type
currentDataT.dataT=Null; declarations are good


For i = 0 To 9
  currentDataT = New dataT
  currentDataT\x = i
  currentDataT\y = i*2
Next

;iterate through list of instances
For currentDataT = Each dataT
	Print currentDataT\x+","+currentDataT\y
Next

WaitKey


Linked lists are pretty useful for games programming and you'll probably end up adopting them sooner or later.

Yep. that functionality surprised and delighted me when I first got blitz. Now, if only we could have separate lists of the same type, like bmax... :)

I'm going to have to try using that on one of my programs. Thanks for the heads up Sledge.

Bear in mind you don't need to DIM an array of types, you can just create loads with the same name and then iterate through them using an EACH loop -
type TYPE_thing
   field x#
end type

;create 10 things
for a=1 to 10
   thing.TYPE_thing = new TYPE_thing
next

;now cycle through them and increment their X positions
for t.TYPE_thing = EACH TYPE_thing
   thing.x# = thing.x# + 1
next


EDIT : just read Sledge's post, which says the same thing. Ah well, never mind :)