Method overwrites or callbacks... how to?

BlitzMax Forums/BlitzMax Programming/Method overwrites or callbacks... how to?

Trader3564(Posted 2008) [#1]
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



_JIM(Posted 2008) [#2]
Try

Field call:Int()



Trader3564(Posted 2008) [#3]
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



Trader3564(Posted 2008) [#4]
Thansk!


EOF(Posted 2008) [#5]
** 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



Trader3564(Posted 2008) [#6]
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



_JIM(Posted 2008) [#7]
I guess it doesn't work because "movement" has a parameter, and "call" doesn't. :)


Czar Flavius(Posted 2008) [#8]
The parameter number and types have to match.


Trader3564(Posted 2008) [#9]
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



Otus(Posted 2008) [#10]
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


Trader3564(Posted 2008) [#11]
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