Calling a constructor from another on the same cla

Monkey Forums/Monkey Programming/Calling a constructor from another on the same cla

Vinians(Posted 2011) [#1]
I'm creating a simple framework for my games and I have a class Actor with 2 constructors see:
Class Actor
        Method New()
		x           = 0
		y	    = 0
		xstart      = x
		ystart      = y
		SetBBox(0, 0, 31, 31)

		sprite      = Null
		image_index = 0
		image_speed = 0
		image_angle = 0
		
		hspeed      = 0
		vspeed      = 0
		active      = True
		visible     = True
		type        = 0
		id          = 0
		room        = Null
	End
        Method New(_x:float, _y:float)
            Self()
            x = _x
            y = _y
        End
End

I tryed using it too
Self.new()


You see ? On the second constructor I call the first constructor first then I set the x and y. Its give-me a error when compiling, but not an error on my app but on the monkey itself, "Error in transcript"... I not tryed it in Monkey full only in demo version.


marksibly(Posted 2011) [#2]
Hi,

Monkey doesn't currently support the use of Self() to invoke other constructors - you'll need to write an 'init()' method or equivalent.