Type global initializer must be constant.

BlitzMax Forums/BlitzMax Programming/Type global initializer must be constant.

JoJo(Posted 2005) [#1]
Does anyone know what this compiler error means? I can't figure it out.

It points to my function inside my type.
Strict
framework brl.max2d
Graphics 640,480,0

'instantiate
Global imgBlue:Image = Image.Create("gfx/blue.bmp")
Global imgGreen:Image = Image.Create("gfx/green.bmp")
Global imgYellow:Image = Image.Create("gfx/yellow.bmp")
Global imgRed:Image = Image.Create("gfx/red.bmp")
Global imgOrange:Image = Image.Create("gfx/orange.bmp")
Global imgPurple:Image = Image.Create("gfx/purple.bmp")

While Not KeyDown(KEY_ESCAPE)

Wend

Type Image
	Global ImageListCount:Int 
	Global ImageList:TList = New TList
	Field xpos,ypos:Int
	Field image:TImage
	Field AlphaLevel:Int
	
	'create
	Function Create:Image(strPath:String)
		Local img:Image = New Image
		img.image = LoadImage(strPath)
		ImageList.AddLast img
		Return img
	End Function	
	
	
	'constructor
	Method New()
		'ImageListCount:+1
		xpos = (GraphicsWidth() / 2)
		ypos = (GraphicsHeight() / 2)
	
	End Method
End Type


Type ExplodeIntoParticles
	Global ParticleList:TList = New TList

End Type



JoJo(Posted 2005) [#2]
I figured it out. It didn't like the two TList variables being inside the types.


Beaker(Posted 2005) [#3]
Its cos you aren't just defining the TList globals, but because you are trying to initialise them with code within the definition.

Reduce them to this:
Global ParticleList:TList


JoJo(Posted 2005) [#4]
Thanks! That works.


BlitzSupport(Posted 2005) [#5]
What I do here is this:

Type Oink

	Global OinkList:TList

	Method New ()
		If OinkList = Null Then OinkList = New TList
	End Method

End Type

It's a single 'If' test that's automatically called on creating a new object -- if Null, create the list; if non-Null, the list already exists. I also like to add 'Self' to the list just after that line...