Method overwrites or callbacks... how to?
BlitzMax Forums/BlitzMax Programming/Method overwrites or callbacks... how to?
| ||
This isnt working, yet it work in JavaScript or PHP. I know this aint any of that, so i wonder what might be the trick here?Type test Field call:Int Method test() Self.call() End Method End Type a = New test a.call = movement a.test() Function movement() Print "yay!" End Function |
| ||
Try Field call:Int() |
| ||
ok this worked.Type test Field call:Int() Method test() Self.call() End Method End Type a:test = New test a.call = movement a.test() Function movement() Print "yay!" End Function |
| ||
Thansk! |
| ||
** EDIT -- snap!Type test Field call:Int() Method test() Self.call() End Method End Type a:test = New test a.call = movement a.test() Function movement() Print "yay!" End Function |
| ||
ok, but this doesnt work. (additionaly, i tried using no parameter and reference to Self. but that is not allowed outside a Type Method) Type test Field parent = Self Field text:String = "blahh!" Field call:Int() Method test() Self.call() End Method Method unload() Self.parent = Null End Method End Type a:test = New test a.call = movement a.test() Function movement(parent:Int) Print parent.text End Function |
| ||
I guess it doesn't work because "movement" has a parameter, and "call" doesn't. :) |
| ||
The parameter number and types have to match. |
| ||
ah... ok, ofcourse!! >_< -edit- hmm.. still doesnt work? Type test Field text:String = "blahh!" Field call:Int(parent:Int) Method test() Self.call(Self) End Method End Type a:test = New test a.call = movement a.test() Function movement(parent:Int) Print parent.text End Function |
| ||
What are you trying to do?Type TTest Field text:String = "blahh!" Field call:Int(parent:TTest) Method test() call(Self) End Method End Type Local a:TTest = New TTest a.call = movement a.test() Function movement(parent:TTest) Print parent.text End Function Edit: fixed a bit... Edit: And once more for clarity |
| ||
Ok, im trying to make a custom movement, which is attachable in runtime. I changed the proto code to something clear for other uses to see as well. Thanks for all the help guys. Type Player Field x:Int Field y:Int Field movement:Int(player:Player) Method setPosition(x:Int, y:Int) Self.x = x Self.y = y End Method Method move() movement(Self) End Method End Type Local a:Player = New Player a.setPosition 32, 64 a.movement = mymovement a.move() Function myMovement(player:Player) Print "moving to: " + player.x + ", " + player.y End Function |