Types from BB3D to BMax

BlitzMax Forums/BlitzMax Beginners Area/Types from BB3D to BMax

pc_tek(Posted 2011) [#1]
Can anybody help me here...I need a simple solution to this problem, and I know that there are probably 100s of solutions to this.

The BB3D Code...

Type ball
	Field x
End Type

For a=1 To 5
	b.ball=New ball
	b\x=Rand(1,10)
Next

For b.ball = Each ball
	Print b\x
Next

WaitKey


...Can anybody transfer this to Max code with the least fuss possible?

Last edited 2011


GfK(Posted 2011) [#2]
Strict

Type ball
	Field x:Float '(or :Int, or :Double)
End Type

Local b:ball
Local myList:TList = New TList

For Local a:Int = 1 To 5
	b = New ball
	b.x=Rand(1,10)
        myList.AddLast(b)
Next

For b = EachIn myList
	Print b.x
Next

WaitKey



pc_tek(Posted 2011) [#3]
Thanks GFK!!

Much appreciated. :)


GfK(Posted 2011) [#4]
Another way:
Strict

Type ball
	Field x:Float '(or :Int, or :Double)
        Method New()
                Self.x = Rand(1,10)
        End Method
End Type

Local myList:TList = New TList

For Local a:Int = 1 To 5
        myList.AddLast(New ball)
Next

For Local b:ball = EachIn myList
	Print b.x
Next

WaitKey


Last edited 2011


H&K(Posted 2011) [#5]
Strict

Type ball

	Global MyList:TList = New TList
	Field x:Float '(or :Int, or :Double)
        
	Method New()
      	Self.x = Rand(1,10)
		Self.Mylist.AddLast(Self)
     End Method
	  
End Type



For Local a:Int = 1 To 5
     New ball
Next

For Local b:ball = EachIn Ball.myList
	Print b.x
Next

WaitKey


NB neither of us have bothered with Deleting/Removing the Balls from the list, but you get the idea


pc_tek(Posted 2011) [#6]
Slowly but surely starting to clear in my head.

Thanks guys.


Czar Flavius(Posted 2011) [#7]
The advantage of this way is you can have multiple seperate lists should you need to.