Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: OhNoMelon on August 23, 2003, 05:34:54 AM



Title: Vocabulary in a text game?
Post by: OhNoMelon on August 23, 2003, 05:34:54 AM
I'm, by no means, an experienced QBasic user. I started playing with it three years ago, making a few very amateurish text games and whatnot. Now I've decided to revisit the whole QBasic scene, because I'm nostalgic for the stuff I used to work on and really loved the environment. As I said, though, I am not terribly experienced, and never worked with anything extremely complicated. I would hand-program each possible response. This worked, of course, but the few who played what I did would complain that it's painfully hard to figure out the exact two words to use. You couldn't "grab key" or "pick up melon" unless I had specifically allowed that combination of words to take the object.

Anyway. After a couple years, I'm going back to the whole thing, and would like to program a text game... but this time, I'd like to do it right. However, I'm really not entirely sure how to set up a sort of "vocabulary" list or common terms, so that I could group a bunch of synonyms, and each would have the same function. It would save a lot of programming. I'm wondering if somebody could help me. How would I go about making a bunch of words synonymous, so they would all perform the same function when they're entered with an INPUT command? I know I'm an amateur and all, and I hate to be such a newbie, but I do have a love for QBasic, even if I could never make anything worth doing more than amusing a couple classmates. Oh well, thanks to anyone that can help me!

Cheers,
Oh No! Melon


Title: Vocabulary in a text game?
Post by: Ruudboy on August 23, 2003, 07:25:13 AM
eamil me and i'll help you with specific questions


Title: hee hee
Post by: Meg on August 23, 2003, 07:52:10 AM
this sounds like a really fun challenge, actually.  I'd love to help out.

let's say that you want to be able to "take" stuff.  so somewhere in this game you're going to have to program some code that "takes" an item (or "get", "pick up", etc.).

the first would be to code a "take" routine.  this would mean you'd make a SUB and you could pass to it a string argument.  For example:

Code:
SUB Command.Take (TakeThisItem$)
  PRINT "You take the "; TakeThisItem$; "and toss it in your pack."
  OPEN "ITEMS.YOU" FOR APPEND AS #1
    PRINT #1, TakeThisItem$
  CLOSE #1
END SUB


now in your program you could make a call to this sub:

Code:
Command.Take "candle"


and it would print to the screen "You take the candle and toss it in your pack." and it would open up a text file called "ITEMS.YOU" and add "candle" on a new line.  Of course, you'd want to make sure there was a candle to pick up first.

now let's back up a bit.  obviously in this text game you're going to be getting string input from the player.  Let's say they're typing in a line of text at a prompt, and that line of text is being stored into a variable called Text$.  Now, the individual letters of that text aren't important.  The only thing you really care about is words, probably.  So maybe you should make an array of strings in which you can store the words.  See if you can follow this logic, and let me know if you have any questions:

Code:
DO

     '*** GET INPUT FROM PLAYER AND TURN IT ALL INTO CAPS ***
     LINE INPUT "> ", Text$
     Text$ = UCASE$(Text$)

     IF LEN(Text$) > 0 THEN
          '*** COUNT THE NUMBER OF WORDS THEY ENTERED ***
          WordCount% = 1
          FOR Letter% = 1 TO LEN(Text$)
               IF MID$(Text$, Letter%, 1) = " " THEN WordCount% = WordCount% + 1
          NEXT Letter%
   
          '*** CREATE A STRING ARRAY TO STORE THE WORDS ***
          REDIM Word$(1 TO WordCount%)
          FOR CurrentWord% = 1 TO WordCount%
               Word$(CurrentWord%) = ""
          NEXT CurrentWord%

          '*** FILL THE ARRAY WITH THE INDIVIDUAL WORDS ***
          CurrentWord% = 1
          FOR Letter% = 1 TO LEN(Text$)
               Letter$ = MID$(Text$, Letter%, 1)
               IF Letter$ = " " THEN
                    CurrentWord% = CurrentWord% + 1
               ELSE
                    Word$(CurrentWord%) = Word$(CurrentWord%) + Letter$
               END IF
          NEXT Letter%
     END IF

     '*** SHOW THE FINAL OUTCOME OF THIS ***
     PRINT "Text$ = "; Text$
     FOR CurrentWord% = 1 TO WordCount%
          PRINT "CurrentWord%("; CurrentWord%; ") = "; Word$(CurrentWord%)
     NEXT CurrentWord%

LOOP UNTIL Text$ = "QUIT" OR Text$ = "EXIT"


Title: Vocabulary in a text game?
Post by: Piptol on August 23, 2003, 09:48:48 AM
Yep, that's a good start by Meg who has shown you how to parse the string input into tokens.

Lets assume we're just dealing with simple two word sentences to start with,  consisting of a verb and object (like "take key" or "kill rat"). So in Megs code, Word$(0) would contain the verb, Word$(1) would have the noun. See if you can work out how this code might fit in with it.

(Disclaimer: top of my head - Untested)
Code:

RESTORE SynonymList
DO
   READ syn$
   IF syn$ = "ENDLIST" THEN verb$ = "UNKNOWN" : EXIT DO
   IF syn$ = UCASE$(syn$) THEN verb$ = syn$
LOOP UNTIL LCASE$(Word$(0)) = syn$

'When you drop out the loop here, verb$ holds the 'base verb'
'so if Word$(0) is "snatch" then verb$ will  be "TAKE".
'If no match then verb$ will be "UNKNOWN"

..........

SynonymList:
'base verbs must be given in CAPITALS
DATA TAKE, grab, snatch, obtain
DATA KILL, maim, destroy, eradicate
DATA THROW, lob, hurl, chuck
DATA ENDLIST


Title: Vocabulary in a text game?
Post by: na_th_an on August 23, 2003, 10:00:06 AM
Should I release my text games library? :D

A good constructed IF game (Interactive Fiction Game) has three main module (in my implementation):

1. Location Manager : Keeps track of where you are, smartly looking in the location files (stuff should be taken away of the BAS to save space), having functions to show the possible exits, managing connectivity and room info, and carrying the "fixed objects" info (objects that you only can examine such as a tree in a street).

2. Parser: This one takes a complete phrase (or several, separated with "." or ",") and it identifies verb, noun, adjective, [noun2, adjective2] basing upon a defined vocabulary. Every unknown word is left out. You can also have synonyms so if you write take or get it always return verb = get. You need this to let your player be able to write in different ways the same things. It will also be capable of parsing multi-command strings (separated by "." ). My parser understands: "get the book. open it. put it in the bag.". It just makes the game loop run three times with:

Code:
loop #1: verb = "get", noun = "book", noun2 = ""
loop #2: verb = "open", noun = "book", noun2 = ""
loop #3: verb = "put", noun = "book", noun2 = "bag"


3. The Object Manager: [this one gave me headaches]: this is the most complex. Basicly, it deals with objects or items you can interact with in the game. Each object has many attributes, such as weight, size, container/non-container, open/close, source-of-light, etc. The Object Manager is which perform actions on the object, so you can take them, wear them, open and close them, turn them on and off, put an object inside another, and stuff. In my test game you had a wallet with coins inside a bag, for example. You have the "visible" FUNCTION wich returns which objects are visible. For example, if the location has light you see every object in your location. If an object that you see is a container and it is open, you also see what's inside the container. And so forth, recursively.

My engine has two problems right now:

1.- It is in Spanish, but I could convert it to English easily as English has a simpler grammar.

2.- It still doesn't handle NPCs.


Title: Vocabulary in a text game?
Post by: ThaMariuZ on August 23, 2003, 01:23:21 PM
hmmm....

how come i only played those text adventures with
multiple choice questions....


Title: Vocabulary in a text game?
Post by: na_th_an on August 23, 2003, 02:37:59 PM
You've missed Interactive Fiction. It is like reading a book and being able to interact with it. I've loved it since I was a child :P There is a really big scene and community. Just google for "Interactive Fiction" with the quotes ;).


Title: Vocabulary in a text game?
Post by: ThaMariuZ on August 23, 2003, 02:42:06 PM
nah, i know what you mean....i have many of these....but
i don't like them...i prefer reading a book...

(especially in germany there were many text adventure
deveoping teams years ago...)

cheers/mariuz


Title: Vocabulary in a text game?
Post by: OhNoMelon on August 23, 2003, 08:05:44 PM
Wow... thanks for your quick replies, everyone! And to think, I used to do things the hard way...

Code:
keyroom: CLS
PRINT "There's a key here. And a horse. And a door."
PRINT
INPUT "What would you like to do"; action$
IF action$ = "take key" THEN GOTO takekey
IF action$ = "get key" THEN GOTO takekey
IF action$ = "pick up key" THEN GOTO takekey
IF action$ = "ride horse" THEN GOTO ridehorse
IF action$ = "mount horse" THEN GOTO ridehorse
IF action$ = "open door" THEN GOTO opendoor
IF action$ = "close door" THEN GOTO doorisnotopen
GOTO keyroom


Etcetera. Anyway. I just skimmed through all that for now, so I'll have to go back and try and make heads or tails of it all... but thank you all very, very much. I really appreciate the fast reply and the willingness to help a fellow out. Now to study the examples... thanks again!

Cheers,
Oh No! Melon


Title: Vocabulary in a text game?
Post by: whitetiger0990 on August 23, 2003, 08:15:36 PM
you could use select case

Code:
keyroom: CLS
PRINT "There's a key here. And a horse. And a door."
PRINT
INPUT "What would you like to do"; action$
SELECT CASE action$
CASE "take key" : GOTO takekey
CASE "get key" : GOTO takekey
CASE "pick up key" : GOTO takekey
CASE "ride horse" : GOTO ridehorse
CASE "mount horse" : GOTO ridehorse
CASE "open door" : GOTO opendoor
CASE "close door" : GOTO doorisnotopen
END SELECT
GOTO keyroom


There i thinks thats right


Title: Vocabulary in a text game?
Post by: OhNoMelon on August 23, 2003, 08:18:13 PM
Well, yeah, but I'm looking for a more efficient way to make the game, instead of using that method. I did make a multiple-choice text adventure with cases, though, back when I first started. It was very, very linear. And more of a guessing game at which choice was right, since I would throw illogical answers in...


Title: Vocabulary in a text game?
Post by: Mech1031 on August 23, 2003, 11:05:18 PM
Send me a Private Message, I used to be into the whole textgame scene, and i had some good shorcuts around stuff like this...


Title: Vocabulary in a text game?
Post by: pr0gger on August 24, 2003, 12:33:50 AM
(Hey! Sounds sorta like a MOO/MUD 8))

You could even do this:


Code:
keyroom: CLS
PRINT "There's a key here. And a horse. And a door."
PRINT
INPUT "What would you like to do"; action$
SELECT CASE action$
CASE "take key", "get key", "pick up key" : GOTO takekey
CASE "ride horse", "mount horse" : GOTO ridehorse
CASE "open door" : GOTO opendoor
CASE "close door" : GOTO doorisnotopen
END SELECT
GOTO keyroom


When you separate with commas in Select Case, it does the same thing as using the OR operator.


Title: Vocabulary in a text game?
Post by: na_th_an on August 24, 2003, 09:38:42 AM
You all haven't read my post ... Well, if you hard code all your rooms that way your game will be lineal and short. Think on QB capabilities...


Title: Vocabulary in a text game?
Post by: OhNoMelon on August 24, 2003, 03:49:17 PM
Heheh, I wasn't really asking how to improve that code, I was just stating the old way I used to use... :lol:


Title: Vocabulary in a text game?
Post by: Moneo on August 25, 2003, 04:34:48 PM
It  occurs to me that instead of allowing the user to enter commands like "take key, get key, pickup key" which all perform the same operation, why don't you present him with a menu of all the operations he can perform. The operations on the menu would be numbered, and the user would select the number for the operation he wants. The description for each operation could contain several versions, like take key, get key, pickup key. All you would have to do is check that he entered a valid operation number, and not worry about all the wording.

What do you think?
*****


Title: Vocabulary in a text game?
Post by: oracle on August 25, 2003, 07:30:08 PM
I think the whole point of that type of game was that people had to experiment to find out what they could type in, though :)


Title: Vocabulary in a text game?
Post by: Moneo on August 25, 2003, 08:16:19 PM
Oh, that wasn't clear to me. :oops:


Title: Vocabulary in a text game?
Post by: na_th_an on August 25, 2003, 09:22:00 PM
Moneo, I'm pretty sure you'll enjoy IFs a lot.

They base themselves on interpreting natural language (not completely, but they come near). It is great that you can try whatever you want, not only following a menu of possible actions.

An example of a game in an IF could be:

1.- The computer gives you a description of where you are:

Quote
At last you arrived to the house. It looks like a very old, small wooden box full of holes. The only entrance is a rusty iron door. The only window is slammed with two thick logs of wood. The athmosphere is misty, you start feeling cold and your clothes are wet. The night is approaching, and you can hear the wails of the coyotes


2.- At this point, the player feels like coming inside the house so he can protect himself against the cold, the rain and the coyotes (extrange combination :D). A simple prompt is offered to the player. "It's your turn":

Quote
>>>_


Then the player can try different things:

Quote
>>> enter house

Sorry, but the door is in your way!.

>>> open door

You try to pull and push, but the door doesn't open.

>>> examine door

It is firmly locked. And you don't have the key.

>>> examine window

Two thick logs are nailed firmly to the wall, avoiding any intruders to come into.

>>> pull logs

They are firmly nailed. You can't move'em just with your strength


The player can try whatever he wants to do (within some limits, of course, but I've seen very complex adventures!). At the end, he or she thinks about his/her pockets, 'cause he/she remembers that he took a took box from the car some locations ago...:

Quote
>>> inventory

You are carrying a heavy toolbox, a wallet and a bottle.

>>> examine toolbox.

It is closed.

>>> open toolbox and examine it.

You open the toolbox.
The toolbox is closed. You find inside a hammer, a tap and a screw.

>>> remove the nails with the hammer

Good idea, but they seem very rusty and don't move

>>> examine bottle

It contains oil from the engine of your car.

>>> use oil in the nails

They seem to be more lubricated now.

>>> remove the nails with the hammer

Done!

>>> remove logs

You remove the logs.

>>> enter house

You enter the house thru' the window


And problem solved! I love this kind of games, they left a lot of room for imagination. A good IF is very well written, so if you enjoy reading this is your kind of games.

My project was making a big IF to play online. A server would carry the game, and every player would connect using a client. The problem is that I don't have enough knowledge about netplay, but I would like to spend some time with this in a near future.


Title: Vocabulary in a text game?
Post by: Moneo on August 25, 2003, 10:02:45 PM
NATHAN,
Yes, that's a very interesting type of game. I would like to try one. What do you suggest, or should I wait for your version? Will yours be bilingual? :wink:
*****


Title: Vocabulary in a text game?
Post by: SCM on August 25, 2003, 11:53:06 PM
Moneo,

This is an ancient one (The Hitchhiker's Guide to the Galaxy):

http://www.douglasadams.com/creations/infocomjava.html#help


Title: Vocabulary in a text game?
Post by: Phydaux on August 26, 2003, 06:07:56 AM
If you really into text adventures, you really should get into IF (like nathan said). There are many languages that have been written, with objects etc., just for this.

Inform (http://www.inform-fiction.org)
TADS (Text Adventure Development System) (http://www.tads.org/)
XYZZY news (http://www.xyzzynews.com)

and the newsgroups (the main part of the IF community):

rec.arts.int-fiction
rec.games.int-fiction


Title: Vocabulary in a text game?
Post by: na_th_an on August 26, 2003, 08:39:05 AM
Thanks, Phydaux, that was what I was gonna sugest ;)

I'd recomend to download the WinFrotz interpreter and "Photopia". Photopia is a great IF, it won many awards when it was released, and also tells a precious story (really sensitive).

I'll dig and provide links :)


Title: Vocabulary in a text game?
Post by: Skyler on June 01, 2006, 04:40:24 PM
Try the IF Archive (www.ifarchive.org). They've got all sorts of IF games. wurb.com/if provides a better interface for finding games in the Archive.


Title: Vocabulary in a text game?
Post by: Peter on June 01, 2006, 05:00:54 PM
(http://fileanchor.com/4785-r.png)


Title: Vocabulary in a text game?
Post by: Anonymous on June 01, 2006, 05:47:40 PM
:bounce:  :bounce:  :mrgreen:


Title: Vocabulary in a text game?
Post by: yetifoot on June 02, 2006, 08:42:15 AM
Did anyone enjoy the InfoCom text adventures?  Hitchhikers Guide To The Galaxy was my favourite (then the zork series).  I would consider them a masterclass in good text adventures.


Title: Vocabulary in a text game?
Post by: SCM on June 02, 2006, 11:41:29 PM
Yetifoot,

See my post on the first page regarding "The Hitchhiker's Guide".  I enjoy Douglas Adam's humor, but I had a very hard time figuring his reasoning.  I had to resort to a hint book to solve the bablefish problem, and I never could solve the main problems of the Heart of Gold.

Steve


Title: Vocabulary in a text game?
Post by: Skyler on June 07, 2006, 06:30:55 PM
AFAIK, Zork is the only InfoCom game i've played, and I tend to prefer storyline-based games to loot-finding games.


Title: Vocabulary in a text game?
Post by: na_th_an on June 12, 2006, 06:31:09 AM
Try photopia on any z-machine then. Awesomeness.


Title: Vocabulary in a text game?
Post by: yetifoot on June 14, 2006, 04:07:27 PM
I can't believe anyone had trouble with the babelfish problem.  I never did complete it though (I think i was also stuck on the heart of gold).  Maybe my memory is hazed as its been about 15 years since i played HHGTTG or Zork.  Lots of the old games i loved seem crap now.