Callig a constructor in a constructor
Monkey Forums/Monkey Programming/Callig a constructor in a constructor
| ||
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? |
| ||
maybe:self.new() |
| ||
Doesn't work. I Tryed:Self() and Self.New() Any sugestion? |
| ||
| smells like a compiler bug to me. |
| ||
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. |
| ||
| This works, but I'm a java programer and in java we can overwrite a constructor, its not possible in monkey ? |
| ||
| it should be that's why I think it's a bug. maybe you should post it in the bug section. |
| ||
| 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. |