samedi 19 janvier 2019

How To Properly Confine IF Command In A Batch File?

I'm attempting to make a little batch file that runs a given command using IF statements based on user input. The 5th option runs multiple commands so to keep it clean I've confined to parenthesis and put it on multiple lines.

However, I can't seem to figure out the proper syntax for making sure that it ONLY runs that option when it is chosen by the user. Regardless of what option you choose, it will run the lines inside the parenthesis of the option 5 anyway. Even worse, choosing any of the options following 5 (so options 6-9) will make you input something to satisfy the input it's waiting for before then actually executing the option you chose for in the first place.

Clearly I'm doing something wrong and the program is following that command no matter what. I apologise for the incredibly noobish question but I've scoured the internet and tried a bunch of different commands and ways of formatting for a good while now. I would be eternally grateful if someone could tell me where I'm going wrong, thank you in advance!

@echo off
cd /d "%~p1"
title Crispy Doom Game Selector
:home
cls
echo.
echo Select Your Game:
echo =================
echo.
echo 1) Ultimate Doom
echo 2) Doom II
echo 3) TNT: Evilution
echo 4) The Plutonia Experiment
echo 5) Master Levels
echo 6) Heretic
echo 7) Chex Quest
echo 8) HacX
echo 9) Exit
echo.
set /p web=Type Number Of Game:
if "%web%"=="1" start crispy-doom.exe -iwad doom\doom.wad -savedir doom\
if "%web%"=="2" start crispy-doom.exe -iwad doom2\doom2.wad -savedir doom2\
if "%web%"=="3" start crispy-doom.exe -iwad doom2\doom2.wad -file doom2\tnt.wad -savedir doom2\
if "%web%"=="4" start crispy-doom.exe -iwad doom2\doom2.wad -file doom2\plutonia.wad -savedir doom2\
if "%web%"=="5" then do (
    echo Which Level?
    dir /s master\
    set /p master=Type Level Name (Without .WAD Extension):
    start crispy-doom.exe -iwad doom2\doom2.wad -file master\%master%.wad -savedir doom2\
)
if "%web%"=="6" start crispy-doom.exe -iwad heretic\heretic.wad -file -savedir heretic\
if "%web%"=="7" start crispy-doom.exe -iwad chex\chex.wad -savedir chex\
if "%web%"=="8" start crispy-doom.exe -iwad hacx\hacx.wad -savedir hacx\
if "%web%"=="9" exit
exit

Aucun commentaire:

Enregistrer un commentaire