Help Please

Previous topic - Next topic

markjd

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.

backslider

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 :)

Ian Price

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 :)
I came. I saw. I played.

BlueSteel

dimed variables have to be accessed with an elemint
eg:

dim bat_y[2]

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


BlueSteel

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

markjd

Thanks guys, removing the tick in explicit declarations worked.

markjd

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 ***

backslider

could you please post your code?
than its easier to help :)

markjd

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 ***

Ian Price

Youve got an extra space between the "[10] [10]" when using DIM. It works when you delete the extra space.
I came. I saw. I played.

markjd

Thanks, how stupid do I feel! Promise to stop bothering you now!

Hemlos

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
Bing ChatGpt is pretty smart :O

markjd

I wondered that but there is no mention of it in the tutorial.

Ian Price

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.
I came. I saw. I played.

Kitty Hello

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.