Variable problem!

Previous topic - Next topic

MrTAToad

Try and compile the following (simple) code with the latest version :

Code (glbasic) Select

GLOBAL KEY_PLAYER1_LEFT% = 0
GLOBAL KEY_PLAYER1_UP% = 1
GLOBAL KEY_PLAYER1_RIGHT% = 2
GLOBAL KEY_PLAYER1_DOWN% = 3
GLOBAL KEY_PLAYER1_BUTTON1% = 4
GLOBAL KEY_PLAYER1_BUTTON2% = 5
GLOBAL KEY_PLAYER1_BUTTON3% = 6
GLOBAL KEY_PLAYER1_BUTTON4% = 7

LOCAL g%

FOR g%=KEY_PLAYER1_BUTTON1% TO KEY_PLAYER1_BUTTON4%
NEXT


Unfortunately it wont compile, and gives the following error message :

Code (glbasic) Select
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp0.cpp:14: error: `KEY_PLAYER1_BUT' was not declared in this scope
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp0.cpp:14: error: `N1' was not declared in this scope
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp0.cpp:14: error: expected `;' before "TO"
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp0.cpp:14: error: `TO' was not declared in this scope
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp0.cpp:14: error: expected `)' before "KEY_PLAYER1_BUTTON4"
C:\Users\Nicholas\AppData\Local\Temp\glbasic\gpc_temp0.cpp:14: error: expected `;' before ')' token
*** FATAL ERROR - Please post this output in the forum


Resulting C Code is :

Code (glbasic) Select
{for (g = KEY_PLAYER1_BUT; g<=N2 TO KEY_PLAYER1_BUTTON4; g++)
{
}


It seems the compile doesn't like KEY_PLAYER1_BUTTON1%, KEY_PLAYER1_BUTTON2%, KEY_PLAYER1_BUTTON3% and KEY_PLAYER1_BUTTON4% to be in a FOR/NEXT loop, and cant tell that part of it isn't part of a keyword :)

Moru

That's funny, if I shorten the length of the names it compiles.

Code (glbasic) Select
// --------------------------------- //
// Project: Testforum 2
// Start: Wednesday, April 08, 2009
// IDE Version: 6.217


GLOBAL KEY_PLAYER1_LEFT% = 0
GLOBAL KEY_PLAYER1_UP% = 1
GLOBAL KEY_PLAYER1_RIGHT% = 2
GLOBAL KEY_PLAYER1_DOWN% = 3
GLOBAL KEY_PLAYER1B1% = 4
GLOBAL KEY_PLAYER1B2% = 5
GLOBAL KEY_PLAYER1B3% = 6
GLOBAL KEY_PLAYER1B4% = 7

FOR g = PLAYER1B3 TO PLAYER1B4
NEXT

Kitty Hello

You can't have variable names with longer than 4 characters!
Joke aside, it's a bug. I'll fix it.