Weird GENSPRITE() and Explicit declarations bug

Previous topic - Next topic

doimus

When using gensprite() function in a project that has "Explicit declarations" turned on, exe crashes immediately.

Everything works fine until I turn on expl.d. After that it crashes no matter whether it's turned on or off subsequently.
It's like turning it on jinxes the compiler... >:D

GLB v7.206

MrTAToad

This is fine for me :

Code (glbasic) Select
LOCAL a%

a%=GENSPRITE()
WHILE TRUE
PRINT a%,100,100
SHOWSCREEN
WEND


With explicit declarations with and without debug mode.

doimus

Do explicit declarations prohibit declaring GLOBAL values?

because if I declare gensprite() variable as global it crashes, if it is declared as local it does not.

Code (glbasic) Select


LOCAL a% = GENSPRITE()
LOCAL b% = GENSPRITE()

PRINT a%, 0,0
PRINT b%, 0,10

SHOWSCREEN
KEYWAIT


This code works the first time it compiles.
Declare any variable as global = BOOM!
Even if I later turn explicit declarations off, I still can't declare global values without crashing!

Also, I'm not entirely sure how gensprite works: in the above code, both a and b are returned as zero. Wasn't it supposed to increment and return b% = 1?


doimus

Damn, I think I got it!
Apparently, I cant declare and assign gensprite() value to the variable in the same line.

ie.
Code (glbasic) Select
global a = gensprite()
is a disaster, but ...

Code (glbasic) Select
global a
a = gensprite()


is fine.



MrTAToad

Yes, RGB is the only command that can be used to initialise variables when defined.

Moru

Yes, that one catches us all sooner or later :-)

doimus

Wonder why? Maybe because it says so in the GENSPRITE() help entry!  :(
C/P from the help file:

Code (glbasic) Select

GLOBAL gImgFoo = GENSPRITE(); LOADSPRITE "foo.png", gImgFoo
GLOBAL gImgBar = GENSPRITE(); LOADSPRITE "bar.png", gImgBar
DRAWSPRITE gImgFoo,0,0
DRAWSPRITE gImgBar,0,100
SHOWSCREEN
MOUSEWAIT