GLBasic forum

Main forum => Bug Reports => Topic started by: Quentin on 2009-Oct-10

Title: PROTOTYPE in combination with TYPE only with constant arguments??
Post by: Quentin on 2009-Oct-10
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

Code: (glbasic) [Select]
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.
Code: (glbasic) [Select]
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:
Title: Re: PROTOTYPE in combination with TYPE only with constant arguments??
Post by: Schranz0r on 2009-Oct-10
this doesn't work, too:
 
 
Code: (glbasic) [Select]

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
Title: Re: PROTOTYPE in combination with TYPE only with constant arguments??
Post by: Schranz0r on 2009-Oct-10
Code: (glbasic) [Select]
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!
Title: Re: PROTOTYPE in combination with TYPE only with constant arguments??
Post by: codegit on 2009-Oct-12
This would be great, but is it going to be possible for Kitty to implement?  :|