Callig a constructor in a constructor

Monkey Forums/Monkey Programming/Callig a constructor in a constructor

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

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. Any solutions?


Jesse(Posted 2011) [#2]
maybe:
self.new()



Vinians(Posted 2011) [#3]
Doesn't work. I Tryed:
Self()

and
Self.New()

Any sugestion?


Jesse(Posted 2011) [#4]
smells like a compiler bug to me.


Jesse(Posted 2011) [#5]
maybe do this instead:

Class Actor
        Method New(_x:float = 0,_y:float = 0)
		x           = _x
		y	    = _y
		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
 End

you can call it with or without parameters.


Vinians(Posted 2011) [#6]
This works, but I'm a java programer and in java we can overwrite a constructor, its not possible in monkey ?


Jesse(Posted 2011) [#7]
it should be that's why I think it's a bug.
maybe you should post it in the bug section.


muddy_shoes(Posted 2011) [#8]
I have an email from Mark back at the beginning of April about this issue. He said that it was possible and even desirable but not yet implemented. I don't recall seeing any mention of it in the release notes, so I guess he hasn't done it yet.