GLBasic forum

Main forum => Tutorials => Topic started by: markjd on 2010-Aug-26

Title: Help Please
Post by: markjd on 2010-Aug-26
I am completely new to programming so please excuse me for being stupid. I have been working through the tutorials in the GLBasic manual, but i am having a problem. When I compile the program I get the error:  error : variable is not explicitly defined : bat_y
This is from the pong tutorial and I have even copied and pasted it to be certain I am not making a typing error.
DIM bat_y[2]
DIM bat_x[2]
DIM score[2]

Any help would be appreciated.
Title: Re: Help Please
Post by: backslider on 2010-Aug-26
Hi markjd and welcome!

I think your problem is not big...

select PROJECT in menubar -> Options.
If the checkbox "explicit declarations" is checked, uncheck it and it should work ;)

This option forces you to declare each variable like in c++
It´s a help if you have hundred of variables :)
Title: Re: Help Please
Post by: Ian Price on 2010-Aug-26
Things have changed in the recent update of GLB; this is actually something I came across a couple of days ago myself. It's to do with explicit coding. You can turn it off, or -

add
Code (glbasic) Select

GLOBAL bat_y[]
GLOBAL bat_x[]
GLOBAl score[]

at the top of your code. All should then be fine.

BTW welcome :)
Title: Re: Help Please
Post by: BlueSteel on 2010-Aug-26
dimed variables have to be accessed with an elemint
eg:

dim bat_y[2]

bat_y[0] = 99
bat_y[1] = 28

Title: Re: Help Please
Post by: BlueSteel on 2010-Aug-26
lol 2 posts posted while i was typing.. hopefully one of us helps ;)
all different answers.. all seeing slightly different angles to answer the question
Title: Re: Help Please
Post by: markjd on 2010-Aug-26
Thanks guys, removing the tick in explicit declarations worked.
Title: Re: Help Please
Post by: markjd on 2010-Aug-26
Ok So I spoke too soon! What does this mean?


*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.8.044 SN:60beea13 - 2D, WIN32
"OneMore.gbas"(8) warning : probably unassigned variable : mx
"OneMore.gbas"(8) warning : probably unassigned variable : my
"OneMore.gbas"(8) warning : probably unassigned variable : b1
"OneMore.gbas"(8) warning : probably unassigned variable : b2
Wordcount:7 commands
compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:25: error: void value not ignored as it ought to be
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.2 sec. Time: 15:27
Build: 0 succeeded.
*** 1 FAILED ***
Title: Re: Help Please
Post by: backslider on 2010-Aug-26
could you please post your code?
than its easier to help :)
Title: Re: Help Please
Post by: markjd on 2010-Aug-26
Sorry, it is from the tutorial.

// Project: One More

DIM playfield [10] [10]
level = 0

// Main game
main:
MOUSESTATE mx, my, b1, b2
PRINT "<=", mx, my-8
SHOWSCREEN
GOTO main
END

When I try to complie and run I get:


*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.8.044 SN:60beea13 - 2D, WIN32
"OneMore.gbas"(8) warning : probably unassigned variable : mx
"OneMore.gbas"(8) warning : probably unassigned variable : my
"OneMore.gbas"(8) warning : probably unassigned variable : b1
"OneMore.gbas"(8) warning : probably unassigned variable : b2
Wordcount:7 commands
compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:25: error: void value not ignored as it ought to be
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.4 sec. Time: 15:29
Build: 0 succeeded.
*** 1 FAILED ***
Title: Re: Help Please
Post by: Ian Price on 2010-Aug-26
Youve got an extra space between the "[10] [10]" when using DIM. It works when you delete the extra space.
Title: Re: Help Please
Post by: markjd on 2010-Aug-26
Thanks, how stupid do I feel! Promise to stop bothering you now!
Title: Re: Help Please
Post by: Hemlos on 2010-Aug-26
In order to clear up some of those other errors, In addition to ians recent post...

mx,my,b1,b2 should be declared, before your main loop begins reading the mouse positions:
Code (glbasic) Select
GLOBAL mx,my,b1,b2
Title: Re: Help Please
Post by: markjd on 2010-Aug-26
I wondered that but there is no mention of it in the tutorial.
Title: Re: Help Please
Post by: Ian Price on 2010-Aug-26
You can live with the error messages - the code will compile and run. Obviously it is best to deal with errors, as they arise (that's where the explicit declaration can help - it won't let your code work if the variables aren't delcared properly - it will also show spelling/case sensitive mistakes). I hate it personally, but it's still useful to have.

But you don't have to declare every variable/array as GLOBAL - you can make them LOCAL in functions, so that they cannot be viewed/altered by other parts of your program.
Title: Re: Help Please
Post by: Kitty Hello on 2010-Aug-26
Quote from: markjd on 2010-Aug-26
Thanks, how stupid do I feel! Promise to stop bothering you now!

How stupid do I feel? That sort of error should not happen at all. Sorry.