View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Any Other Words?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1Damon E. Washington  Members

Posted 22 March 2014 - 06:22 AM

Hey Everyone.

I've been working on a text adventure game in CMD.

I have all my inputs and what-not entered, but I was curious if there was a way to have CMD state "I don't recognize this ____" (____ = object, or command, or verb, etc..) if the player inputs something it does not recognize.

Lets say my inputs are as follows:

if %input1% equ bed goto bed_1
if %input1% equ door goto door_1
if %input1% equ TV goto tv_1
...


Now the basic flow is as follows:

Player: Examine

CMD: Examine What?

Player: ______

In the blank if the player was to put "knife" and there was no knife I want CMD to say it does not recognize that.

Is there a "if %input1% (does not equal) bed,door,TV say (or goto) 'I dont recognize this' "

Let me know if you need me to clarify anything.

- Damon E. Washington

### #2DareDeveloper  Members

Posted 22 March 2014 - 08:18 AM

Not 100% sure if I understand what you are asking, but if I do, usually that is accomplished by making it the last condition ... so it is called if none of the known words applies (no explicit check if the word is not known, it is implicitly checked, because goto would have been called and the code would not have been reached).

Goto weirds me out, usually it is a loop over a list of words or if / else if / else statements ...

but you should be able to use a goto without any condition at the end, unless the context that it is taken out of does not allow that.

if %input1% equ bed goto bed_1
if %input1% equ door goto door_1
if %input1% equ TV goto tv_1
goto unknown_1

If that is not helpful you might need to specify the question / explain the situation in more detail ...

I don't recognize the language, but if there are containers that can store the known objects, then an explicit check would be possible - there are usually contains-methods that let you check if a list contains the object (String object in this case).

Edited by DareDeveloper, 22 March 2014 - 08:26 AM.

Given enough eyeballs, all mysteries are shallow.

### #3Damon E. Washington  Members

Posted 23 March 2014 - 05:24 AM

Hey,

Yeah sorry I should've been more clear.

For the sake of understanding lets use examples.

Imagine in a text adventure game you are in a room with a TV and a couch.

If you input "use" and then "TV" the game will display a short message.

What I would like is if you input "use" then "knife" the game will display a message telling you there is no knife.'

I would like all nouns/verbs that are unusable to have this feature.

So, say thee only verbs you could use are: use, take, push, and examine.

If someone says "pull" the game will say it doesnt understand that command.

Is their anyway to group every unusable command at once inside of coding 1000 lines of code for 1000 incorrect inputs?

(See now, if CMD detects something it doesnt know it will just reply the last message it showed or just crash...).

Hope that cleared things up...

- Damon E. Washington

### #4DareDeveloper  Members

Posted 23 March 2014 - 06:31 AM

What do you have in place already? I guess it looks something like that?

:OutputState
Loop over gamestates in gamestates.txt, extract the description and echo it

:PromtAction
Goto HandleAction

:PromptObject
Write prompt message appropriate for current action
Goto HandleObjectAction

:PromptUseWith
Goto HandleUseWith

:HandleAction
Handle known action if no object is needed and goto PromptAction or OutputState
Goto PromptObject if a known action requires it
Goto PromptAction or OutputState

:HandleObjectAction
loop over objects.txt, extract the information you need for the action/object
Goto PromptUseWith if the object was found and the action requires another object
Handle object action if the object was found (set new gamestate) and goto PromptAction or OutputState
Goto PromptAction or OutputState

:HandleUseWith
loop over usewith.txt, extract the information you need for the action/objects
Handle object action if the object was found (set new gamestate) and goto PromptAction or OutputState
Goto PromptAction or OutputState



Commands would still be hardcoded, but you could read comma separated values files for the gamestate descriptions and object descriptions, gamestate changes etc. and assign the values of the record to variables.

In Bash I would probably use cat and sed, not sure what options CMD offers.

Any reason why you did not go for something more ... modern?

Edited by DareDeveloper, 23 March 2014 - 06:32 AM.

Given enough eyeballs, all mysteries are shallow.

### #5Damon E. Washington  Members

Posted 23 March 2014 - 03:11 PM

Ok so here is a good example of my code:

:push_4
echo.
echo Push What?
echo.

set /p input27=Enter:

if %input27% equ metal goto metal_push_3
if %input27% equ bed goto bed_push_4
if %input27% equ brick goto brick_push_4
if %input27% equ bars goto bars_push_4
if %input27% equ liquid goto liquid_push_4

:metal_push_3
echo.
echo You have no reason to push, or touch that again.
echo.
goto home_4

:bed_push_4
echo.
echo The bed has been pushed up to the bars already.
echo.
goto home_4

:brick_push_4
echo.
echo You push the brick in.
echo.
goto End_1

:bars_push_4
echo.
echo You push the bars with all your might, but they refuse to budge.
echo.
goto home_4

:liquid_push_4
echo.
echo Pushing it would require touching it...
echo and you surely don't want to do that.
echo.
goto home_4

If the player inputs "push" and then "knife" when there clearly is none, that is when I want the "I don't recognize that" message to play...

Would the above still apply?

And I know CMD is a buggy, old pain

But, I am creating a text-adventure so those were buggy pains in a nutshell... plus how can play a text adventure without it being in CMD... it doesnt feel the same if its not .

### #6DareDeveloper  Members

Posted 23 March 2014 - 03:54 PM

Well yes, instead of doing it this way

if %input27% equ metal goto metal_push_3
if %input27% equ bed goto bed_push_4
if %input27% equ brick goto brick_push_4
if %input27% equ bars goto bars_push_4
if %input27% equ liquid goto liquid_push_4


you would search the file for an occurrence of the word that the user has entered and store the text that should be displayed in a variable then always print the value of that variable if it does not equal an emptry string. Again, I know how I would do that in Bash, I only assume that there is a way to do something similar in CMD.

Guess you should think of a better way to handle gamestates. Try to have one push method and check the gamestate there. If you duplicate code like that you will develop more bad habits than actually gain valuable experience.

With the approach that I have outlined you could have one object file per gamestate.

Also ... many languages allow you to create a console application that you can execute from the command line. I bet most text-adventures were not written as command line scripts.

There are articles about writing text adventures. It might be helpful to read some of those to see how other people write a parser and deal with gamestates.

Given enough eyeballs, all mysteries are shallow.

### #7Damon E. Washington  Members

Posted 23 March 2014 - 06:22 PM

Hey!

Thanks for all the info!

Very much appreciated.

I'll check out the text-adventure articles .

Thanks Again,

- Damon E. Washington

### #8Satharis  Members

Posted 23 March 2014 - 11:05 PM

This is a pretty common thing that had to be implemented in early text games, especially stuff like MUD's. Generally you tokenize up the text and check the first word to determine the kind of action, then the action may have some kind of specific behavior relative to the item.

For instance if you wanted to "get dodo" you would probably clean up the text a bit(remove whitespace and tokenize it) then you might want to take the first word and put it to lowercase, checking it against a command list. Since you would end up with "get" you might call some function and pass it the rest of the tokens, changing how you interpret it based on how many words there are, if theres just one it might be as simple as using some code to search the room for a "dodo" and if all else fails you then know that the object or thing in question isn't present.

That's the basic train of thought for that kind of system, you can make it as simple or complex as you want really.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.