Creating more than 1 object for a list...

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

po(Posted 2006) [#1]
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?


Dreamora(Posted 2006) [#2]
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.


po(Posted 2006) [#3]
Ah, right. Never thought of that, heh.


TomToad(Posted 2006) [#4]
Actually, since you are storing the type into a list, you shouldn't need Return at all. This code works:



H&K(Posted 2006) [#5]
All you have to do is remove the return

Edit: oh


po(Posted 2006) [#6]
Huh. Thanks.