Author Topic: Help Please  (Read 6126 times)

Offline markjd

  • Mc. Print
  • *
  • Posts: 7
    • View Profile
Help Please
« 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.

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Help Please
« Reply #1 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 :)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4147
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Help Please
« Reply #2 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 :)
I came. I saw. I played.

Offline BlueSteel

  • Mc. Print
  • *
  • Posts: 39
  • Jack of ALL codes .. master of none :(
    • View Profile
    • Coding Monkeys
Re: Help Please
« Reply #3 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


Offline BlueSteel

  • Mc. Print
  • *
  • Posts: 39
  • Jack of ALL codes .. master of none :(
    • View Profile
    • Coding Monkeys
Re: Help Please
« Reply #4 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

Offline markjd

  • Mc. Print
  • *
  • Posts: 7
    • View Profile
Re: Help Please
« Reply #5 on: 2010-Aug-26 »
Thanks guys, removing the tick in explicit declarations worked.

Offline markjd

  • Mc. Print
  • *
  • Posts: 7
    • View Profile
Re: Help Please
« Reply #6 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 ***

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Help Please
« Reply #7 on: 2010-Aug-26 »
could you please post your code?
than its easier to help :)

Offline markjd

  • Mc. Print
  • *
  • Posts: 7
    • View Profile
Re: Help Please
« Reply #8 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 ***

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4147
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Help Please
« Reply #9 on: 2010-Aug-26 »
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.

Offline markjd

  • Mc. Print
  • *
  • Posts: 7
    • View Profile
Re: Help Please
« Reply #10 on: 2010-Aug-26 »
Thanks, how stupid do I feel! Promise to stop bothering you now!

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Re: Help Please
« Reply #11 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
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline markjd

  • Mc. Print
  • *
  • Posts: 7
    • View Profile
Re: Help Please
« Reply #12 on: 2010-Aug-26 »
I wondered that but there is no mention of it in the tutorial.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4147
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Help Please
« Reply #13 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.
I came. I saw. I played.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10713
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Help Please
« Reply #14 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.