Need help with a game

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Zeph
Posts: 1
Joined: 26 Mar 2019 18:01

Need help with a game

#1 Post by Zeph » 26 Mar 2019 18:25

So, I will try to explain my problem. I am making a narrative game in batch, and I have a little problem (in fact I have two). This is the code I have problem with :
*This is basically a chat interface where you discuss with somebody and you have to make choices in the discussion)

Code: Select all

echo                        -----------------
echo ------------------Answers choice----------------------------------                  
echo "[1] Hello Roger, I am the employee responsible for your file" ---------------------------
echo "[2] I will not go there four ways, you will die if you do not convince me otherwise!"
echo -------------------------------------------------------------------------------------------------------
set /p var=Me: 
if %var%==1 goto Answer1.1
if %var%==2 goto Answer1.2
:else1
echo Roger: I don't understand what are you saying?
timeout /t 3 /nobreak >nul
goto Tchat1
:Answer1.1
echo Roger: Hello sir, where should I start?
pause
:Answer1.2
echo Roger: I am really stressed... I
When you are writing which option you want to choose I want the text of your answer to be echo just after the "Me: ", now it is just marking 1. The other thing is that I want the all "Answers choice" part to be deleted. To resume, I want this to be printed when you make your choice:
Me: Hello Roger, I am the employee responsible for your file
Roger: I don't understand, What are you saying ?

Thank you for taking the time to read this and for trying to solve my problem ! :P

IcarusLives
Posts: 114
Joined: 17 Jan 2016 23:55

Re: Need help with a game

#2 Post by IcarusLives » 28 Mar 2019 07:07

One important thing to remember is that batch scripts run from top to bottom.
I want the text of your answer to be echo just after the "Me: ", now it is just marking 1. The other thing is that I want the all "Answers choice" part to be deleted.
You need to remember that you have not mapped an array to these answers. When the user is inputting, they're literally inputting "1", and that "1" in your case is not mapped to an array element.

For example:

Code: Select all

set "array[1]=Hello Roger, I am the employee responsible for your file"
set "array[2]=I will not go there four ways, you will die if you do not convince me otherwise!"
Now you can say take %var%

Code: Select all

set /p var=Me: 
You can access the information like so

Code: Select all

call echo %%array[%var%]%%
Here is everything you need to do this, so hopefully this is what you were looking for

Code: Select all

@echo off

set "array[1]=Hello Roger, I am the employee responsible for your file"
set "array[2]=I will not go there four ways, you will die if you do not convince me otherwise!"

set /p "var=Me: "

call echo %%array[%var%]%%

Aacini
Expert
Posts: 1598
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: Need help with a game

#3 Post by Aacini » 28 Mar 2019 13:17

Something like this, perhaps?

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set "Answer1.1=Hello Roger, I am the employee responsible for your file"
set "Answer1.2=I will not go there four ways, you will die if you do not convince me otherwise^!"
set "Answer1.3=Terminate these questions"

cls
:loop
echo/
echo/
echo ------------------Answers choice----------------------------------
for /L %%i in (1,1,3) do echo !Answer1.%%i!
echo ------------------------------------------------------------------

set /P "=Me: " < nul
choice /C 123 > nul
echo !Answer1.%errorlevel%!
goto Answer1.%errorlevel%

:Answer1.1
echo Roger: Hello sir, where should I start?
pause
goto loop

:Answer1.2
echo Roger: I am really stressed...
pause
goto loop

:Answer1.3
echo Roger: Bye...
goto :EOF
Antonio

Post Reply