Creating more than 1 object for a list...

BlitzMax Forums/BlitzMax Beginners Area/Creating more than 1 object for a list...

Type TProps

	Field x:Int,y:Int,size:Int

	Global EntityList:TList=New TList
	
	Method Draw()		
	
	End Method 
	
	Method New()
		EntityList.AddLast(Self)
	End Method
	
	Function Create:TProps(amount:Int)
	
		For Local i:Int=0 To amount-1			
	
			Local p:TProps=New TProps		
				Local size:Int=Rnd(25,35)
				p.size=size			
				p.x=0'Rnd(0,100)
				p.y=Rnd(0,(100)							
			Return p	
		
		Next
		
	End Function

End Type


Why does the code in the Create function only return one p? What do I need to do to create the amount of p's?

You need to call create more than once.


Return can only return one object and when the code reaches return, it will actually leave the function. (read the docs on what the keywords do, seems like you have some elemental missassumption on how the keywords work currently.

Ah, right. Never thought of that, heh.

Actually, since you are storing the type into a list, you shouldn't need Return at all. This code works:
Type TProps

	Field x:Int,y:Int,size:Int

	Global EntityList:TList=New TList
	
	Function Draw()	
		For Local Prop:TProps = EachIn EntityList
			DrawOval Prop.x, Prop.y, Prop.size, Prop.size
		Next	
	
	End Function 
	
	Method New()
		EntityList.AddLast(Self)
	End Method
	
	Function Create(amount:Int)
	
		For Local i:Int=0 To amount-1			
	
			Local p:TProps=New TProps		
			Local size:Int=Rand(25,35)
			p.size=size			
			p.x=Rand(0,799)
			p.y=Rand(0,599)							
		
		Next
	End Function	

End Type

Graphics 800,600,32
SeedRnd(MilliSecs())

TProps.Create(10)

While Not KeyHit(KEY_ESCAPE)
	TProps.Draw()
	Flip
Wend


All you have to do is remove the return

Edit: oh

Huh. Thanks.