New [C:\bmx\regaa/littleShooter.bmx;49;1]

BlitzMax Forums/BlitzMax Programming/New [C:\bmx\regaa/littleShooter.bmx;49;1]

regaa(Posted 2004) [#1]
What does this line mean? Here s some code:

Strict

Const GWIDTH=800
Const GHEIGHT=600


Type starfield Extends Spiel
Field x
Field y

Method Create:StarField(x:Int=0, y:Int=0)
If x=0 Then x=rnd(0,GWIDTH)
If y=0 Then y=rnd(0,GHEIGHT)
End method

Method Draw()

End Method
End Type

Type Screen
Field w=800
Field h=600

Method Create:screen(width=800,height=600)
If width<>w Then width=w
If height<>h Then height=h

Graphics width,height,0,60
End Method
End Type

Type Spiel
Field Bild:Screen=New Screen
Field Bg:Starfield=New Starfield

Method Init()
Bild.Create()
End Method

Method Render()
Cls
Bg.Draw()
FlushMem()
Flip()
End method
End type

Local Game:Spiel=New Spiel '<----- BUG? IAMSTUPID? IAMANEWB?
Print "Initialisiert"
Game.Init()

While Not KeyDown(KEY_ESCAPE)
Game.Render()
Wend


taxlerendiosk(Posted 2004) [#2]
BlitzMax clearly doesn't like it if you use "New" in a field definition. It's those "New"s that are causing the problem, not the "New" you have commented. I don't know why this is, but I'm sure someone will be along in a minute to explain. Anyway, change the beginning of Spiel to this:
Type Spiel
	Field Bild:Screen
	Field Bg:Starfield

	Method Init()
		Bild = New Screen
		Bild.Create()
		Bg = New Starfield
	End Method
    ...



regaa(Posted 2004) [#3]
Ahhh, now i got it :). Thx


Perturbatio(Posted 2004) [#4]
You can define new objects in the field definition.

Surely creating something of type Spiel that has a field of type Starfield that extends type Spiel would cause issues though?


taxlerendiosk(Posted 2004) [#5]
I don't see why?


FlameDuck(Posted 2004) [#6]
I don't see why?
Because it's recursive?


taxlerendiosk(Posted 2004) [#7]
Ah, of course, now I see.