Creating Types

BlitzMax Forums/BlitzMax Beginners Area/Creating Types

Eikon(Posted 2005) [#1]
In the old Blitz I was able to create a type inside of a type loop without problems, as long as it was in an external function. Whenever I try to do this with BlitzMax, it creates a recursive loop and the program freezes. What I'm trying to do is create a new type whose position is based off of an existing one in the same list. Is there a way to do this in Max?

Graphics 640, 480, 0, -1

Global objList:TList = New TList, o:Obj

Type Obj
	Field X, Y

	Method Render()
		DrawRect X, Y, 1, 1
		X:+1
		CreateObj X, Y

	End Method

End Type

Repeat
Cls

For o:Obj = EachIn ObjList; o.Render; Next

If MouseHit(1) Then CreateObj 320, 240

FlushMem; Flip
Until KeyDown(KEY_ESCAPE)

Function CreateObj(X, Y)
o:Obj = New Obj
o.X = X; o.Y = Y

objList.AddLast o
End Function



FlameDuck(Posted 2005) [#2]
Whenever I try to do this with BlitzMax, it creates a recursive loop and the program freezes
You are creating a new object your "Render" method, and thus adding one to the list of objects to render. It's not a recursive loop, as much as it is a never ending one (as each time you go to the next item in the queue, a new one is added to the end).


Eikon(Posted 2005) [#3]
I got it working now. Thank you