• Advertisement
Sign in to follow this  

Qbasic Prob?

This topic is 4550 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
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.

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
but when you have to do like 50 different area descriptions, wouldnt that get a little hectic if it is all twined together?
*edit* scratch that, it actually is more organized in a sort, thanks for help every one ^_^.

[Edited by - EmptyMinion on September 5, 2005 1:38:16 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyMinion
but when you have to do like 50 different area descriptions, wouldnt that get a little hectic if it is all twined together?

It certainly can. The area descriptions can be read in as an array of STRINGS. These descriptions can further be enclosed in a TYPE/ENDTYPE structure, which can also be stored in an array, or another TYPE.

Keep in mind the kinds of things that each location would need:

''' QBasic TYPEs can only hold fixed-length STRINGs
CONST MAXDESCRIPTORLENGTH% = 256

''' a TYPE is a user-defined data type, containing one or more elements
''' of either basic or user-defined TYPEs
TYPE Location
descriptor AS STRING * MAXDESCRIPTORLENGTH

dirEast AS INTEGER ''' in the initializing part of your
dirWest AS INTEGER ''' program, each of these might be
dirNorth AS INTEGER ''' set to TRUE or FALSE, depending
dirSouth AS INTEGER ''' on whether that exit is available

''' and more
END TYPE

''' and later define some locations
DIM Bathroom AS Location
DIM Hallway AS Location

''' you'd want to get these values from a file rather than hard-code them
Bathroom.descriptor = "The toilet hasn't been flushed in weeks ..."
Bathroom.dirEast = TRUE
Bathroom.dirWest = FALSE
Bathroom.dirNorth = FALSE
''' etc...


This helps keep code light and organized. TYPEs are like structs in C, albeit very crippled versions, that allow you to make pseudo-objects that have mutliple properties. Using constructs like this greatly reduces code size, and increases readability, reusability. Experiment with TYPEs, and for further study, read up on SUBs and FUNCTIONs. Two items that are guaranteed to un-twine much of your code.

Share this post


Link to post
Share on other sites
could i make a diff file for each area and have it load when it changes direction? cuz i am gettin confused on backtracking and multiple ways to get to an area. lol
http://www.geocities.com/emptyminion/Screen.bmp --- there screenshot so far of wht goin on ^_^

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyMinion
could i make a diff file for each area and have it load when it changes direction?

You could, but then you'd be accessing the hard-drive every area. To avoid this, you can load all of your areas at once, when your program starts up.

Quote:
cuz i am gettin confused on backtracking and multiple ways to get to an area.

Here's a modest approach:

TYPE Area
descriptor AS STRING * 30

handle AS INTEGER ''' this is the handle of this area
AreatoEast AS INTEGER ''' these act as handles or pointers
AreatoWest AS INTEGER ''' to other areas
AreatoNorth AS INTEGER
AreatoSouth AS INTEGER
''' additional properties here ...
END TYPE

''' then when it is time to load the areas,
''' open data file and store area TYPEs
OPEN "areas.ini" FOR INPUT AS #1 ''' open a file for reading from
DIM numAreas AS INTEGER
INPUT #1, numAreas ''' sotre the total number of areas
DIM AreaArray( numAreas ) AS Area ''' DIMension an array big enough to all them all

DIM a AS INTEGER
FOR a = 1 to numAreas ''' iterate through all areas
INPUT #1, AreaArray( a ).handle ''' INPUT (read) TYPE's elements from file
INPUT #1, AreaArray( a ).AreatoEast ''' ...
INPUT #1, AreaArray( a ).AreatoWest
INPUT #1, AreaArray( a ).AreatoNorth
INPUT #1, AreaArray( a ).AreatoSouth
''' and any other elements to read ...
NEXT R
CLOSE #1




The handle is an index into the master array. The AreatoXXXX handles contain an index to the area that it is connected to. The first area you read will have a handle of 1. If AreaArray(1).AreatoEast = 14, then going EAST from that area takes you to the area with a handle of 14 (the 14th element in the master array). If AreaArray(1).AreatoNorth = 0, (for example), then there is no exit to the north.

If you have alot of areas, you might want to code an area editor. Regardless, you'll probably want to draw out your area design. The data file you read from will be a text file. INPUT# reads words seperated by spaces, commas, EOL, carraige return or line feed. The hard part (time consuming) is enumerating the handles.

A file could look like this:

areas.ini:

4
1, "This is the study ", 0, 4, 0, 2
2, "This is the hallway ", 0, 0, 1, 3
3, "This is the kitchen ", 0, 0, 2, 0
4, "This is a closet of the study", 1, 0, 0, 0

Again, since QBasic TYPEs can only have fixed-length strings, we need to have each string the maximum size that it will be (MAXDESCRIPTORLENGTH). If you end up writing an editor for this, then it makes it about 5 times easier than doing it by hand (and much less error-prone as well)

Quote:
http://www.geocities.com/emptyminion/Screen.bmp --- there screenshot so far of wht goin on ^_^

Looks good so far!

EDIT: my syntax may be off - it's been awhile with QBasic :(

Share this post


Link to post
Share on other sites
what would i use to make a area editor lol. seems like the most reasonable aproach, cuz it gunna be a well sized game lol.

Share this post


Link to post
Share on other sites
You can write one in QBasic. Create an Area array, then use a DO/LOOP UNTIL statement to INPUT your Area TYPE elements (desciption, handles, etc.). You can terminate the loop by checking a boolean (true or false). OPEN a file for writing, PRINT# the total number of areas that you entered first. Then PRINT# your areas to the file.

DIM AreaArray( 1 to 200 ) AS Area ''' allocate a well-sized array
DIM numAreas AS INTEGER ''' keeps a runing total of areas
DIM done AS INTEGER ''' tells us we're done entering areas

numAreas = 0;
done = FALSE
DO
numAreas = numAreas + 1

? "area #"; numAreas
? "---------------------"
LINE INPUT "descriptor: "; Area( numAreas ).descriptor

IF AreaArray( numAreas ).descriptor = "" THEN
numAreas = numAreas - 1
done = TRUE
ELSE
LINE INPUT "handle to east exit: "; AreaArray( numAreas ).AreatoEast
LINE INPUT "handle to west exit: "; AreaArray( numAreas ).AreatoWest
LINE INPUT "handle to north exit: "; AreaArray( numAreas ).AreatoNorth
LINE INPUT "handle to south exit: "; AreaArray( numAreas ).AreatoSouth
ENDIF

LOOP UNTIL done



Then PRINT# to the file using a FOR/NEXT loop with the iterator as your index into AreaArray(). The handle that a particular area uses to define itself can be the iterator itself. Thus:
OPEN "areas.ini" FOR OUTPUT AS #1
PRINT #1, numAreas

FOR i = 1 to numAreas
PRINT #1, AreaArray( i ).descriptor
PRINT #1, i
PRINT #1, AreaArray( i ).AreatoEast
PRINT #1, AreaArray( i ).AreatoWest
PRINT #1, AreaArray( i ).AreatoNorth
PRINT #1, AreaArray( i ).AreatoSouth
NEXT i

CLOSE #1



That should get you started. EDIT: VB highlighted :/

Share this post


Link to post
Share on other sites
? is a shortcut for PRINT. Sorry, I was typing kinda fast when I wrote that.

Share this post


Link to post
Share on other sites
also would it be better if i learned python for a editor kind of situation, and where would i get the stuff i need for python if so?

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyMinion
also would it be better if i learned python for a editor kind of situation, and where would i get the stuff i need for python if so?

I'm not familiar with Python, but I believe there should be links here on GameDev. Actually, go here:

list of free gaming libraries

I also hear that VisaulBasic is great at designing tools within Windows environments, and the syntax is quite similar to what you're used to.

If you want to stick with QBasic, let me tell you that a simple room editor (like the one I described above) is definitely doable, although that approach almosts necessitates pre-organizing and planning, two skills which are very important, by the way. Working with a Windows' editor opens many doors and may slice development time, but there's the overhead of learning Windows' programming, at least to some extent.

Like I said, I can't vouche for Python, but VB is nice. Just remember what you want to spnd your time on: an editor, or a game?

Share this post


Link to post
Share on other sites
so visual basic would be good to create an application that is capable of making a text game? i might have to give that a try, in consideration that my friend wants to be able to use my editor too, once it is done.
*edit* visual basic costs money? :( is there a free version? lol

[Edited by - EmptyMinion on September 6, 2005 7:44:59 PM]

Share this post


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

  • Advertisement