Im building a game and whenever i pick Credits, Help or Exit it starts the game.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
thelegend27
Posts: 1
Joined: 18 Aug 2019 17:50

Im building a game and whenever i pick Credits, Help or Exit it starts the game.

#1 Post by thelegend27 » 18 Aug 2019 17:55

Heres the code.

Code: Select all

-- Above this is a bunch of menu decor.
ECHO 1 - Start Game
ECHO 2 - Credits
ECHO 3 - Help
ECHO 4 - Exit
ECHO.
SET /P M=Type 1, 2, 3, or 4 then press ENTER:
IF %M%==1 GOTO game
IF %M%==2 GOTO credits
IF %M%==3 GOTO help
IF %M%==4 EXIT
PAUSE
EXIT

:help
cls
ECHO Sorry, it appears that help is not supported in this version. Download the next version when it comes out!

:credits
cls
ECHO Zachary Myrden - Head and Creator of project TCOE

:game
cls
ECHO You wake up in a dark place.... There seems to be a glass shard nearby... Pick it up? [Y/N]
SET /P M=Type Press Y and enter to pick it up. N and enter to leave it alone.
IF %M%==Y SET %dmgid%=1 GOTO S1Y1
IF %M%==N GOTO S1N1

:s1y1
cls
ECHO You picked up "Glass Shard"!
PAUSE
EXIT

:s1n1
cls
ECHO You decide to leave the glass shard alone.
PAUSE
EXIT

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Im building a game and whenever i pick Credits, Help or Exit it starts the game.

#2 Post by penpen » 18 Aug 2019 19:26

You don't use "goto :<defined label>", "goto :eof", "exit /b", "exit".
It is recommended to use functions, which you also have to (untested):

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
call :func1
call :func2
call :func1
goto :eof

:func1
echo Hello from func1.
goto :eof

:func2
echo Hello from func2.
goto :eof
penpen

Post Reply