Small text game

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Thomasjpollard687
Posts: 1
Joined: 05 Jun 2017 14:03

Small text game

#1 Post by Thomasjpollard687 » 05 Jun 2017 14:34

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

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Small text game

#2 Post by misol101 » 06 Jun 2017 09:49

You could use my Interactive Fiction parser: :mrgreen:

viewtopic.php?f=3&t=7246&p=47674

Just add datafiles to make a new game, no need to code batch :)

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Small text game

#3 Post by Compo » 06 Jun 2017 12:10

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

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: Small text game

#4 Post by PaperTronics » 23 Jun 2017 22:59

A few tips for you

1. Use the Code formatting whenever pasting any

Code: Select all

code
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.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Small text game

#5 Post by ShadowThief » 23 Jun 2017 23:47

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).

Post Reply