PROTOTYPE in combination with TYPE only with constant arguments??

Previous topic - Next topic

Quentin

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:

Schranz0r

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
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Schranz0r

Quote from: Quentin 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!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

codegit

This would be great, but is it going to be possible for Kitty to implement?  :|
------------------------------------------
1 X Acer TravelMate 4270, laptop, XP PRO
1 X Dell Studio 17 laptop, Windows 7
1 X MacBook Pro 2,2 GHz Core 2 Duo, 2 GB RAM, 160 GB HDD, 9400M
2 X iTouch
1 X HTC Desire (Android 2.1)
iPad soon to be added