-4

I want to make a game where you are on a computer and you type 1 to get to files, but if you type something random like d it closes the window. How can I fix this?

My code:

set /p Location=Where do you want to go: 
goto %Location%
  1. I want to make a game similar to "Welcome To The Game".
  2. All the other code for now is echo's and what's at the top.
  3. Location is what you are in like files or internet explorer.
  4. The code is inside one batch file only.

Okay don't worry about this it's a duplicate and I've gotten my answers.

AdamBRaps
  • 13
  • 6
  • Can you elaborate a little on what you're trying to do? Do you have any other code? Can you give some examples of "Location"? Are you trying to go to a different directory within Windows within the command prompt launched by your bat script? Such as Location = C:/users/someone, then change the current working directory to the C:/users/someone directory? – Birdman Dec 08 '18 at 08:51
  • one (very simple) way to fix it is using the [choice](https://ss64.com/nt/choice.html) command instead. – Stephan Dec 08 '18 at 19:19

1 Answers1

0

For example:

@echo off
echo.
echo Where do you want to go?
echo.
echo 1 file1
echo 2 file2
echo 3 file3
echo.
set /p Location="User input:"
if "%Location%" == "1" goto file1
if "%Location%" == "2" goto file2
if "%Location%" == "3" goto file3
pause >nul

:file1

:file2

:file3
Marko Žlender
  • 68
  • 1
  • 1
  • 7