Jump to content
  • Advertisement
Sign in to follow this  
EmptyMinion

Qbasic Prob?

This topic is 4731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You could use some globals for your directions ...

''' directions
CONST 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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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-z
CONST TRUE = 1
CONST FALSE = 0

DIM choice AS STRING
DIM directionFound AS INTEGER
directionFound = FALSE

DO
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 SELECT
LOOP UNTIL directionFound

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!