Can seem to itterate my user types

BlitzMax Forums/BlitzMax Beginners Area/Can seem to itterate my user types

D4NM4N(Posted 2006) [#1]
In b3d if i wanted a simple data structure ie:

for a=1 to 10
mt.mytype=new mytype
mt\blah=a
next

for mt.mytype=each mytype
print mt\blah
next

Ive tried to do the same in max obviously changing \ fo . . for \ and each for eachin, but now im getting something about lists? what is this, is the list to be global local? In otherwords where does it fit in to the general scheme of things?

The example in the code seems to imply i have to create a list localy and fill it somehow with my entire type structure, simply to recurse all data in said type?!?

why does this need to be so complicated?


tonyg(Posted 2006) [#2]
In Bmax the objects *HAVE* to be put on your own list. B3D did this for you (1 big list) but in BMax you can have multiple lists.
Try this very basic example...
Type TTest
  Field x
End Type
mylist:Tlist=CreateList()
For x = 1 To 100
   mynew:TTest = New ttest
   mynew.x = x
   ListAddLast mylist,mynew
Next
For all:TTest = EachIn mylist
   Print all.x
Next

and read this...
Beginners Guide

<edit> The list can be in any scope you intend to use it. If connected to a type then the list can be defined within the type definition itself.
<edit> More OOP way of doing it...
Type TTest
  Global mylist:TList
  Field x
  Function create(x)
     If mylist=Null mylist:TList=CreateList()
     mynew:ttest = New ttest
     mynew.x = x
     ListAddLast mylist,mynew
  End Function
  Method display()
     Print x
  End Method
End Type
For x = 1 To 100
  ttest.create(x)
Next
For all:TTest = EachIn ttest.mylist
   all.display()
Next



Beaker(Posted 2006) [#3]
Useful as well:
http://www.blitzbasic.com/Community/posts.php?topic=50285


D4NM4N(Posted 2006) [#4]
Ahhh right.. quite powerful then!
Thanks