Qbasic Prob?

Started by
19 comments, last by EmptyMinion 18 years, 7 months ago
cls color 15 print "(Area Description)" color 4 print "Exits are- East, West, South, North" How would i make it so when you type east, it changes you to a different location using labels?
Advertisement
Store user input from INPUT$ into a variable. If you wish to use labels, compare user input against each direction ( "east", "west", etc. ) you want to test for and GOTO a particular LABEL in a set of IF/ENDIF statements. The QBasic Help should be able to teach you how to use the above keywords with some quick reading. (just type in the name of the keyword, and press F1.)

But keep in mind that the GOTO statement has been deemed 'hackish' over recent years, almost to the point of taboo. Using the GOTO statement in your code generally makes it harder to read, debug and maintain. Other built-in flow-control statements (SELECT/CASE, WHILE/WEND, DO/LOOP, etc.) are preferred.
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
i know all about em, i just forgot to add $ to the input ^_^ lol and this is a first project game so i think goto will work fine for now ^_^ thanks for help
^_^ ... 3 in a row!
*edit*- still cant get it to reconize the string east, can some one provide a simple example code of it please.
a good idea is to convert your input to lowercase for easier parsing. It's eaiser to compare 'east' to 'east' or just 'e' then have to worry about any or all of the letters being caps.
it is all lowercase in the original code im workin on, i just cant get the statement to work right--
if choice$ = east$ then
goto 1
end if
... (do same thing for north, but goto 2)
1 : Print "East"
2 : Print "North"

even when i use north it still prints east... and then north, why?
We'd have to see how you're assigning choice$ and east$ earlier in your code. Also, after jumping to 1:, the code will continue on to 2:. You need yet another GOTO after 1:. It's a snowball effect ... Consider not using GOTO.
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
wht good way to assign east, and even when u chose north and it suppose to go to 2, it prints east, then north still.
You could use some globals for your directions ...
''' directionsCONST D_EAST$ = "east"CONST D_WEST$ = "west"CONST D_NORTH$ = "north"CONST D_SOUTH$ = "south"

As for your flow-control problem, show some source code so we can see what it is you're doing.
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
just use SELECT CASE instead, I also use LCASE$ to convert choice$ into lower case:

SELECT CASE LCASE$(choice$)  CASE "east"    print "You went East"  CASE "west"    print "You went West"  CASE "south"    print "You went South"  CASE "north"    print "You went North"END SELECT

It greatly simplifies the code rather than GOTOing everywhere :)
Quote:Original post by dmatter
just use SELECT CASE instead ...

Invariably, you'll want to have a CASE ELSE in there to deal with erroneous user input. Or ... :
DEFINT a-zCONST TRUE = 1CONST FALSE = 0DIM choice AS STRINGDIM directionFound AS INTEGERdirectionFound = FALSEDO   LINE INPUT "Enter a direction: "; choice$   SELECT CASE LCASE$(choice$)      CASE "east"         PRINT "You went East"         directionFound = TRUE      CASE "west"         PRINT "You went West"         directionFound = TRUE      CASE "south"         PRINT "You went South"         directionFound = TRUE      CASE "north"         PRINT "You went North"         directionFound = TRUE   END SELECTLOOP UNTIL directionFound
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid

This topic is closed to new replies.

Advertisement