I am making a game using batch, but it won't run (WINDOWS 10)

Xenerlicious820

Commendable
May 18, 2016
2
0
1,510
I wanted to make a game using batch script, yet it opens and closes extremely quickly. Please be descriptive I'm pretty new

The Code:
@echo off
title Just Do It! By: Ryan Clark
color 0A
:start
cls
echo.
echo ###### CRASH LANDING ######
echo # #
echo # 1. Start #
echo # 2. How To Play #
echo # #
echo ###########################
if %opl%==1 goto game
if %opl%==2 goto inst

:inst
cls
echo.
echo This game was created by Ryan Clark 2016.
echo HOW TO PLAY
echo PICK UP ITEM: pick up [item]
echo EXAMINE: examine [item]
echp FIGHT: fight [enemy] with [weapon]
:game
cls
echo.
echo You are very excited as you a board a plane for vacation
echo You will be flying to the Bahamas
echo In your carry on bag






pause
 
Solution
It is just like the pause at the end of your batch.

It was posted in the code above with a pause then to goto start. It should work fine.

If you mean an exit it would just be

Code:
echo ###### CRASH LANDING ######
echo # #
echo # 1. Start #
echo # 2. How To Play #
echo # 3. Exit or Quit #
echo # #
echo ###########################

set /p op1="This is where you ask for a number "
if "%op1%" == "1" goto game
if "%op1%" == "2" goto inst
if "%op1%" == 3" goto quit

You can add :quit at the bottom of the file with an exit command to close the window.

In order to make the game you will likely need many variables so that the user can perform all the required actions. This is the place that other programming languages may be better.

ShadeTreeTech

Distinguished
Jun 23, 2011
95
0
18,660
your goto statement doesn't have an input. Open a command prompt, and then run your batch file. To add input you can add a line before your if statements. set /p opl="Select: " This will set your opl variable to whatever is selected by keyboard input.

On a side note, nothing wrong with batch programming to get started. I would recommend Powershell, or Virtual Basic, but that's just my opinion.
 
You may also want to add a pause(or else it will just fly into the game) and goto start(if you want to re-enter the menu) after the :inst section

Adding a exit on the menu may be a good idea too.

Code:
@echo off
title Just Do It! By: Ryan Clark
color 0A
:start
cls
echo.
echo ###### CRASH LANDING ######
echo # #
echo # 1. Start #
echo # 2. How To Play #
echo # #
echo ###########################
set /p op1=""
if "%op1%" == "1" goto game
if "%op1%" == "2" goto inst

:inst
cls
echo.
echo This game was created by Ryan Clark 2016.
echo HOW TO PLAY
echo PICK UP ITEM: pick up [item]
echo EXAMINE: examine [item]
echo FIGHT: fight [enemy] with [weapon]
Pause
goto start

:game
cls
echo.
echo You are very excited as you a board a plane for vacation
echo You will be flying to the Bahamas
echo In your carry on bag






pause
 
It is just like the pause at the end of your batch.

It was posted in the code above with a pause then to goto start. It should work fine.

If you mean an exit it would just be

Code:
echo ###### CRASH LANDING ######
echo # #
echo # 1. Start #
echo # 2. How To Play #
echo # 3. Exit or Quit #
echo # #
echo ###########################

set /p op1="This is where you ask for a number "
if "%op1%" == "1" goto game
if "%op1%" == "2" goto inst
if "%op1%" == 3" goto quit

You can add :quit at the bottom of the file with an exit command to close the window.

In order to make the game you will likely need many variables so that the user can perform all the required actions. This is the place that other programming languages may be better.
 
Solution