Solved Small Text Game Help

June 5, 2017 at 14:46:21
Specs: Windows 10
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%==lookatman goto :1" but I cannot use "if %opt%==look at man goto :1"

I don't know why, If you could help me (completely new btw) I would be most grateful,

- Thomas


See More: Small Text Game Help

Reply ↓  Report •

#1
June 5, 2017 at 18:00:47
✔ Best Answer
1) I keep saying this, but if you're on an OS developed since the 1980's, you shouldn't be doing anything requiring any significant effort in batch. This goes double for Win10, since Microsoft is starting to deprecate it. The good news is any other language you'd pick up will have been actually designed, which is something batch cannot claim.

2) There has been more effort towards text parsers than I've ever cared to delve into, but if you're interested, feel free to read up: https://www.google.com/#q=interacti...

3) If you're going to insist on batch (may your gods have mercy on your soul), you need to use double quotes around your string comparisons: if "%opt%"=="look at man" goto :1

How To Ask Questions The Smart Way


Reply ↓  Report •

#2
June 6, 2017 at 03:34:58
Thanks mate you really helped
cheers - Thomas

Reply ↓  Report •
Related Solutions


Ask Question