the new PROTOTYPE command works fine, but I found something strange when using them in TYPES
the small example below will give a an error "Call to undefined function : TPlayer"
If I replace the line
player.ptr_init(100, 100, player.graphic)
with
player.ptr_init(100, 100, 0)
it works without error. Seems when using prototypes in types, only constant arguments can be used? Without types I can use variable arguments. :S
PROTOTYPE Init: x, y, graphic
TYPE TPlayer
x; y
graphic
ptr_init AS Init
ENDTYPE
GLOBAL player AS TPlayer
DRAWRECT 0, 0, 20, 20, RGB(255, 255, 0)
player.graphic = GENSPRITE()
GRABSPRITE player.graphic, 0, 0, 20, 20
player.ptr_init = InitPlayer
player.ptr_init(100, 100, player.graphic)
SHOWSCREEN
KEYWAIT
// ------------------------------------------------------------- //
// --- INITPLAYER ---
// ------------------------------------------------------------- //
FUNCTION InitPlayer: px, py, pgraphic
PRINT "x:" + px + "y:" + py + "Graphic:" + pgraphic, 0, 0
ENDFUNCTION // INITPLAYER
Furthermore it's not allowed to initialize function pointers within the TYPE declaration
e.g.
PROTOTYPE Init: x, y, graphic
TYPE TPlayer
x; y
graphic
ptr_init AS Init = InitPlayer
ENDTYPE
GLOBAL player AS TPlayer
// ------------------------------------------------------------- //
// --- INITPLAYER ---
// ------------------------------------------------------------- //
FUNCTION InitPlayer: px, py, pgraphic
PRINT "x:" + px + "y:" + py + "Graphic:" + pgraphic, 0, 0
ENDFUNCTION // INITPLAYER
This will give me a syntax error. Would be nice if this was possible too :whistle:
this doesn't work, too:
PROTOTYPE _create: mt AS TTest, text$, x%, y%
TYPE TTest
x%;y%
text$
create AS _create
ENDTYPE
GLOBAL _TTest[] AS TTest
LOCAL t AS TTest
t.create = CreateTTest
t.create(t, "test",10,20)
WHILE TRUE
PRINT t.text$, t.x, t.y
SHOWSCREEN
WEND
END
FUNCTION CreateTTest: t AS TTest, text$, x%, y%
t.x = x
t.y = y
t.text$ = text$
ENDFUNCTION
Quote from: Quentin on 2009-Oct-10
PROTOTYPE Init: x, y, graphic
TYPE TPlayer
x; y
graphic
ptr_init AS Init = InitPlayer
ENDTYPE
GLOBAL player AS TPlayer
// ------------------------------------------------------------- //
// --- INITPLAYER ---
// ------------------------------------------------------------- //
FUNCTION InitPlayer: px, py, pgraphic
PRINT "x:" + px + "y:" + py + "Graphic:" + pgraphic, 0, 0
ENDFUNCTION // INITPLAYER
This would be the way to use!
This would be great, but is it going to be possible for Kitty to implement? :|