I know it may sound pretty lame, however, I have tried everything and I assume (hope) you guys can help me.
I am trying to create a small, text adventure game (like on the recent game 'Stories Untold - The House Abandon.') But I cant seem to get it to work like I want it to. I can do a numbered choice type like this:
Do you?
echo 1. Walk up to the man
echo 2. Avoid him
Enter Choice:
But I really want to create a system where you just type in what you want to do. So far I have this test piece and it works up until I press enter:
@echo off
:start
ECHO a man stands beside a wall
ping localhost -n 1 >nul
set /p opt= :
if %opt%==look man goto :1
if %opt%==look at man goto :2
if %opt%==view man goto :3
:1
Echo The man is dressed in a green jacket, blue jeans
ping localhost -n 4 >nul
cls
:2
Echo The man is dressed in a green jacket, blue jeans
ping localhost -n 4 >nul
cls
:3
Echo The man is dressed in a green jacket, blue jeans
ping localhost -n 4 >nul
cls
I have found that you cannot use more than one word (anything with a space) e.g. I can use "if %opt%==lookman goto :1" but I cannot use "if %opt%==look man goto :1"
I don't know why, If you could help me (completely new btw) I would be most grateful,
- Thomas
Small text game
Moderator: DosItHelp
Re: Small text game
You could use my Interactive Fiction parser:
viewtopic.php?f=3&t=7246&p=47674
Just add datafiles to make a new game, no need to code batch
viewtopic.php?f=3&t=7246&p=47674
Just add datafiles to make a new game, no need to code batch
Re: Small text game
For a simple fix you just need to doublequote your string comparisons.
Code: Select all
@Echo Off
:start
Echo a man stands beside a wall
>Nul Timeout 1
Set/P "opt= : "
If /I "%opt%"=="look man" GoTo :1
…
-
- Posts: 118
- Joined: 02 Apr 2017 06:11
Re: Small text game
A few tips for you
1. Use the Code formatting whenever pasting any on Dostips
2. You should use the TIMEOUT command instead of ping -localhost. I used the ping command to pause the cmd console too when I was a beginner Batch programmer.
3. Be sure to use the if /I switch whenever using the if command to check user input as the /I switch checks for both, capital and small letters. E.g if the user input is "yes" the the normal if will detect the input easily. However, if the user input is "Yes" then the if command will fail to detect it.
1. Use the Code formatting whenever pasting any
Code: Select all
code
2. You should use the TIMEOUT command instead of ping -localhost. I used the ping command to pause the cmd console too when I was a beginner Batch programmer.
3. Be sure to use the if /I switch whenever using the if command to check user input as the /I switch checks for both, capital and small letters. E.g if the user input is "yes" the the normal if will detect the input easily. However, if the user input is "Yes" then the if command will fail to detect it.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Small text game
1. Good advice.
2. Timeout doesn't exist in XP, and ping can be used for pauses of less than one second.
3. For those of you without screen readers and who don't feel like copying and pasting, that's a capital i, not a lower case L. It's also worth mentioning that flags are not case-sensitive (nor are basically anything in batch except for loop variables).
2. Timeout doesn't exist in XP, and ping can be used for pauses of less than one second.
3. For those of you without screen readers and who don't feel like copying and pasting, that's a capital i, not a lower case L. It's also worth mentioning that flags are not case-sensitive (nor are basically anything in batch except for loop variables).