"For each" problem with types

Blitz3D Forums/Blitz3D Beginners Area/"For each" problem with types

You can do this:
For N = 1 to 10
  A.t1 = new t1
  A\num1 = rand(0,100)
Next
That code uses variable A ten times to add ten items to the t1 type collection, so the collection contains ten items.

If you then do this:
For N = 1 to 10
  B.t1 = new t1
  B\num1 = rand(0,100)
Next

...the t1 type collection will now contain 20 items.

In a nutshell, it doesn't matter what variable you use - A, B, whatever, as they're all added to the T1 type collection in the end, and using more than one variable to do it is a waste, really.

If you need to distinguish between one and the other, then you can either create another type (t2, for instance), OR you can add a further Field to your existing type.
Type t1 
  Field num1 
  Field Class
End Type
You can then iterate through the whole type collection with a For...Each loop, analyse the contents of the 'Class' field, and execute the appropriate bit of code.
For A.t1 = Each t1
  If A\Class = 1
    ;Do something
  EndIf
  If A\Class = 2
    ;Do something else
  EndIf
Next