GLBasic forum

Main forum => GLBasic - en => Topic started by: DHeadshot on 2010-Jun-08

Title: FOR loop issues
Post by: DHeadshot on 2010-Jun-08
Hi, just a slight issue.  Whenever I try to do anything useful with for loops, I get something like this:
Code (glbasic) Select

C:\DOCUME~1\(Username removed)\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\(Username removed)\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:89: error: `n' was not declared in this scope
*** FATAL ERROR - Please post this output in the forum

the related code will be simply a FOR loop with something inside it.  This exact errormessage was generated from this:
Code (glbasic) Select
LET n=1
FOR n=0 TO 1 STEP 0.1
ALPHAMODE n
LOADSPRITE "(Filename Removed)",0
DRAWSPRITE 0, 300, 150
SHOWSCREEN
KEYWAIT
NEXT

Any ideas?
Title: Re: FOR loop issues
Post by: MrTAToad on 2010-Jun-08
That error message means that you have enabled explicit variable declaration and haven't defined the variable "n"
Title: Re: FOR loop issues
Post by: DHeadshot on 2010-Jun-08
There is nothing in the help about option explicit and I haven't touched anything.

Edit:  I found the Option Explicit box.  It's not ticked.  Any other ideas?

This is why I hate anything that has anything to do with C - things always go wrong when the C bit compiles.  C is the worst language ever made (yes, that includes COBOL and Malbolge) as it will often randomly decide it hates you and won't work.
Title: Re: FOR loop issues
Post by: Ian Price on 2010-Jun-08
Remove the "LET n=1" and it works.
Title: Re: FOR loop issues
Post by: DHeadshot on 2010-Jun-08
I tried that before and it didn't work.  However, I've just tried again and it has.  Any idea why it randomly changed it's mind (other than the fact that C does that in my experience)?
Title: Re: FOR loop issues
Post by: Schranz0r on 2010-Jun-08
LOCAL n#


;) btw: LET is out!
Title: Re: FOR loop issues
Post by: MrTAToad on 2010-Jun-08
LET probably checks to see if the variable is defined when you assign a value - and thus you get the message...

Quote(other than the fact that C does that in my experience)
The only time it will seem to do this is overwriting random parts of memory - which is due to programmer error...

Have you recently updated your copy of GLBasic ?
Title: Re: FOR loop issues
Post by: DHeadshot on 2010-Jun-08
Did it earlier today, when I first started it up...

As for LET, I like to stick it in if something isn't working, just to see if that's the problem...
Title: Re: FOR loop issues
Post by: com_1 on 2010-Jun-08
LOADSPRITE "sprite.png",1;

n=0.0015;


WHILE TRUE

IF n<1; n=n+0.0015;ENDIF;

ALPHAMODE -n; DRAWSPRITE 1, 300, 150; ALPHAMODE 0;

SHOWSCREEN; WEND