GLBasic forum

Main forum => GLBasic - en => Topic started by: pnunbe on 2013-Feb-04

Title: Variable not explicitly defined
Post by: pnunbe on 2013-Feb-04
 Hi,
I have a program where, before the game loop, there is the following statement:
DIM classe$[2][2]
When I compile the program the following message appears:
----------------------------------------
Random.gbas"(32) error : variable is not explicitly defined : classe$
----------------------------------------
The strangest thing is that in one of the sample programs (The First Game) the same structure does not give rise to any problem.
What did I miss?
Best regards

Title: Re: Variable not explicitly defined
Post by: kanonet on 2013-Feb-04
You either need to define the variable 1st, by using using LOCAL/GLOBAL/STATIC, or turn of explicit declarations in the project options. Please use the search funtions if you need more informations about this issue, there are many threads about this.
Title: Re: Variable not explicitly defined
Post by: bigsofty on 2013-Feb-04
Make sure the variable is not locally defined in a function elsewhere.
Title: Re: Variable not explicitly defined
Post by: Schranz0r on 2013-Feb-04
Hehe, ok :)
Like kanonet say:

Code (glbasic) Select


LOCAL classe$
DIM classe[2][2]



@ Gernot( if you read this) :

Is there any way to do something like ( v11 :P ):

Code (glbasic) Select

GLOBAL DIM classe[2][2]


?? ;)
Title: Re: Variable not explicitly defined
Post by: BdR on 2013-Feb-04
In the GLBasic menu, go to "Project" -> "Options" and there is a checkbox "Explicit declarations". If this is checked, you must declare all your variables. You can uncheck it and you won't get the error message. However, I would recommend you always have this option enabled (checked).

For example, look at the following code:
Code (glbasic) Select
mystring$ = "test"
PRINT mysting$, 10, 10


With "Explicit declarations" enabled, you'll get an error and you'll quickly notice the typo "mysting$" instead of "mystring$". When it's disabled it will just compile, automatically create 2 variables "mysting$" and "mystring$" and the code doesn't print anything, and then you have to go find the mistake yourself. ;)
Title: Re: Variable not explicitly defined
Post by: doimus on 2013-Feb-05
Quote from: BdR on 2013-Feb-04

With "Explicit declarations" enabled, you'll get an error and you'll quickly notice the typo "mysting$" instead of "mystring$". When it's disabled it will just compile, automatically create 2 variables "mysting$" and "mystring$" and the code doesn't print anything, and then you have to go find the mistake yourself. ;)

Oh yeah... makes me think of Python... Beautiful, powerful scripting language. But all hell breaks loose if you have a typo in variable name or wrongly placed whitespace indent.  =D

Then there are C style languages where you spend more time writing declarations than actual implementations.

And GLBasic once again sits in the golden middle!  :good: