75Views3Replies

Author Options:

Why Won't my Batch Game Not work? Answered

I made it so some parts got to the section area Finish 1 Which everytime a goto command goes to it the cmd prompt crashes and the batch game wont work. [Finish 1 is at the bottom]


@echo off
title Mystic
color 5d

:Password
echo Enter Your Username and Password
echo.
set /p user=Enter UserID:
set /p pass=Enter Password:

if /i %user%==PerfectSpike1337 (
    if /i %pass%==ABCDEFG123456 goto Naming)

if not "%input%" == ABCDEFG123456 goto Incorrect

:Incorrect
cls
echo Wrong password, Please ask Kellen McDonald for the Password.
pause >nul
goto Password

:Naming
cls
echo Please enter an avatar name of your desire.
echo.
set /p uname=
echo.
echo Welcome to Mystic RPG %uname%
echo.
echo Press 1 to get started
echo Press 2 to exit
set /p input=Enter:
if "%input%" == "1" goto :Getting Started
if "%input%" == "2" exit
if "%input%" == "" goto Naming
if "%input%" == "Admin Code 123" goto Stab 1


:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Naming

:A
cls
echo You were injured and sent to the hospital. Don't try that again.
pause >nul
ping localhost -n 2 >nul
cls
echo Waking Up.
ping localhost -n 2 >nul
cls
echo Waking Up..
ping localhost -n 2 >nul
cls
echo You have woken up, the nurse greets you.
pause >nul
echo.
echo Welcome back %uname%, press 1 to restart at the bank.
set /p input=Enter:
if "%input%" == "1" goto :Bank
if "%input%" == "" goto A

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto A


:Getting Started
echo You will recieve your free gold to get started %uname%, first you must walk to the
echo bank.
pause >nul
echo Walking.
ping localhost -n 2 >nul
cls
echo Walking..
ping localhost -n 2 >nul
cls
echo Walking...
ping localhost -n 2 >nul
cls
echo Choose what you want.
echo 1. Enter Bank
echo 2. Rob Bank
set /p input=Enter:
if "%input%" == "1" goto Bank
if "%input%" == "2" goto A
if "%input%" == "" goto Getting Started
pause >nul

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Getting Started


:Bank
echo You have arrived at the Bank Of Gen Town!
pause >nul
echo "Here's your money %uname%"
pause >nul
echo Grabbing Money.
ping localhost -n 2 >nul
cls
echo Grabbing Money..
ping localhost -n 2 >nul
cls
echo You Have recieved 500 GenDol!
pause >nul
cls
echo Press 1 to begin your next task!
set /p input=Enter:
if "%input%" == "1" goto Sword Shopping
if "%input%" == "" goto Bank

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Bank


:Sword Shopping
echo You now have enough GenDol for an iron sword at the GenMarket!
echo.
echo You may now walk to the Market.
pause >nul
cls
echo Press 1 to walk to the market.
set /p input=Enter:
if "%input%" == "1" goto Shopping
if "%input%" == "" goto Sword Shopping

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Sword Shopping

:Shopping
echo You will now start walking to the Market.
pause >nul
echo Walking.
ping localhost -n 2 >nul
cls
echo Walking..
ping localhost -n 2 >nul
cls
echo Walking...
ping localhost -n 2 >nul
cls
echo Enter 1 to enter the market!
set /p input=Enter:
if "%input%" == "1" goto Market
if "%input%" == "" goto Shopping

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Shopping


:Market
echo "Welcome to the GenMarket %uname%!"
pause >nul
echo Here is some of our items you can buy!
echo.
echo 1. Iron Sword [500 GenDol, 10 attack]
echo 2. Golden Sword [750 GenDol, 15 attack]
echo 3. Dark Matter Sword [5000 GenDol, 100 attack]
echo.
echo Enter the number of the sword you want to buy!
set /p input=Enter:
if "%input%" == "1" goto Iron Sword
if "%input%" == "2" goto Need GenDol
if "%input%" == "3" goto Need GenDol
if "%input%" == "" goto Market

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Market


:Need GenDol
echo You don't have enough GenDol for that!
echo Come back later with more GenDol!
echo.
echo Enter 1 to return to the market screen.
set /p input=Enter:
if "%input%" == "1" goto Market
if "%input%" == "" goto Need GenDol

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Need GenDol


:Iron Sword
echo You have now bought the Iron Sword and is equipped!
echo.
echo You may now begin your journey!
echo.
echo Press 1 to start your journey!
set /p input=Enter:
if "%input%" == "1" goto Road 1
if "%input%" == "" goto Iron Sword

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Iron Sword


:Road 1
echo You see a Bandit! [50 HP]
echo.
echo What will you do?
echo.
echo 1. Attack The Bandit
echo 2. Sneak By The Bandit
set /p input=Enter:
if "%input%" == "1" goto Battle 1
if "%input%" == "2" goto Get Spotted

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Road 1


:Battle 1
cls
echo You have challenged the Bandit to a duel!
echo.
echo Choose what you will like to do!
echo.
echo [100 STAMINA LEFT]
echo 1. Swing (5 STAMINA) [10 Damage]
echo 2. Stab (10 STAMINA) [15 Damage]
set /p input=Enter:
if "%input%" == "1" goto Swing
if "%input%" == "2" goto Stab
if "%input%" == "" goto Battle 1

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Battle 1


:Get Spotted
echo The Bandit has spotted you try to sneak by him!
echo.
echo The Bandit has challenged you to a duel, prepare to battle!
echo.
echo Press 1 to enter the duel!
set /p input=Enter:
if "%input%" == "1" goto Battle 1
if "%input%" == "" goto Get Spotted
:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Get Spotted

:Stab 1
echo You lunge at the Bandit!
echo Your attack hit!
echo The attack damaged the Bandit critically!
echo.
echo [The Bandit Loses 30 HP]
echo.
echo The Bandit has lunged at you!
echo [You Have Lost 10 HP, 90 HP Left]
echo.
echo Enter 1 to finish The Bandit!
set /p input=Enter:
if "%input%" == "1" goto Finish 1
if "%input%" == "" goto Stab

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Stab


:Swing 1
echo Your attack hit!
echo The attack damaged the Bandit critically!
echo.
echo [The Bandit Loses 25 HP]
echo.
echo The Bandit has lunged at you!
echo [You Have Lost 10 HP, 90 HP Left]
echo.
echo Enter 1 to finish The Bandit!
set /p input=Enter:
if "%input%" == "1" goto Finish 1
if "%input%" == "" goto Swing

:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Swing


:Finish 1
echo You have finished off the Bandit!
echo.
echo You have recieved 25 EXP and 65 GenDol!
echo Your current status is [25|100 EXP]
echo.
echo You have recieved 10 extra HP for your first win!
echo You are now at full HP! [100|100 HP]
echo.
echo Would you like to continue down this trail or camp
echo for the night? [Enter the Numbers 1-3]
echo.
echo 1. Continue down the trail
echo 2. Camp The Night
echo 3. View Inventory
set /p input=Enter:
if "%input%" == "1" goto Trail 1
if "%input%" == "2" goto Camp 1
if "%input%" == "3" goto Inventory 1


:Bug Fix
echo No cheating!
pause >nul
echo Prepare for teleportation back!
ping localhost -n 2 >nul
echo 1..
ping localhost -n 2 >nul
cls
echo 2..
ping localhost -n 2 >nul
cls
echo Go!
cls
goto Finish 1



:Trail 1
pause >nul


:Camp 1
pause >nul


:Inventory 1
pause >nul

Discussions

0
Nighter3D
Nighter3D

4 years ago

quickly did some debugging by copying your project and jumping to the function and found your problem!

the '|' symbol in your echo posts are causing the crash. | is a command symbol which overides the ECHO. To get around this add a ^ right before it.

So instead of "echo Your current status is [25|100 EXP]"

have it say "echo Your current status is [25^|100 EXP]" (notice the ^).

0
verence
verence

4 years ago

Hey, that is far too long to be analysed by anyone, who may want to help you. Try to shorten it to the minimum (like one or two goto, only a few echos ...)

Anyway, I'm not sure that goto labels can have spaces, so try Finish1 instead of Finish 1.

What happens if the user enters something else but 1,2,3 in Finish 1? The batch will just continue with the Bug Fix part.

0
Nighter3D
Nighter3D

Answer 4 years ago

quick check shows that Goto labels can have spaces. not the best practice, but it doesn't cause any issues.