Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / GOTO Problem...

Author
Message
superSully
21
Years of Service
User Offline
Joined: 17th Oct 2003
Location: location, location, location
Posted: 23rd Oct 2003 07:34
Hey

I'm having problems with my program, (its kinda dumb but everyone's got to start programming somewhere) in the use of a GOTO command. I have the GOTO command set up, i tell it where to go and i can't get it to go anywhere but the same place (even though there are 3 different places that it goto) plz someone check this out!

Thanks
Sully

PS: the problem occurs at lines 26 thru 32 and goto will still take the program to "yes"

hey this is my signature i guess
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd Oct 2003 10:10
I haven't looked at your code but I can tell you (as many here will too) DON'T USE GOTO - period!

Put your code in a sub or function and call it with GOSUB or function call...that way the program can return to execution correctly/safely. GOTO is open-ended nasty rubbish that is no longer necessary in these days of higher thinking/technology.

-RUST-
KNau
22
Years of Service
User Offline
Joined: 25th Nov 2002
Location: Canada
Posted: 23rd Oct 2003 10:27
CattleRustler is right. When a goto jumps to one of the points in your code, like this spot:



The game jumps to that point in the code and then runs as normal, right through to the end of your code - including through all your other GOTOs. Also it runs so fast the the above "IF RETURNKEY() = 1 THEN GOTO thing" is skipped past long before you have the chance to hit the return key.

For simplicity you could switch to GOSUBs instead. A gosub will jump to the point you tell it to and then jump back to where it came from when it reaches a RETURN command. Therefore it won't run through all of your other subroutines.

http://www.canceriannewmedia.com
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 23rd Oct 2003 14:59 Edited at: 23rd Oct 2003 15:04
The error is in this line
INPUT INKEY$()
Inkey$() is a function, but Input needs a variable, like Input A$

and in the following if conditions
IF ASC(INKEY$())=y
GOTO yes
endif

Beside the Inkey$ problem described above, there are a couple of other mistakes. Let's say we have
INPUT$ A$
Now the user types in Y
ASC(A$) would return 89 (ASCII for Y)
So
IF ASC(A$) = y
would resolve in
IF 89 = 0
Why 0? because y is a variable, initialised to 0.

The correct line would be
IF UPPER$(A$) = "Y" ...

The same applies to the following IF blocks too



As for the GOTO command, I wouldn't say "never use GOTO" 'cause then I'd have to say "never use EXIT", as well. My advice is "use GOTO seldom".

I awoke in a fever. The bedclothes were all soaked in sweat.
She said "You've been having a nightmare and it's not over yet"
superSully
21
Years of Service
User Offline
Joined: 17th Oct 2003
Location: location, location, location
Posted: 24th Oct 2003 07:29
thanx i got it all to work

hey this is my signature i guess

Login to post a reply

Server time is: 2024-11-25 14:35:46
Your offset time is: 2024-11-25 14:35:46