Solved Please help, is there something wrong somewhere?

April 17, 2017 at 02:07:50
Specs: Windows 10
Hi I'm pretty new to batch script so I can't diagnose the problem I'm having with anything other than failure to read the script or max script char limit (the second one is very unlikely). My code is below the problem specifically is that PART4 in my code won't appear on the window and instead when I get there it closes the window. Please help me. Thanks in advance.
@echo off
title Test Game
color 02
:INTRO
cls
echo Welcome to TBC by WackeyTech!
echo.
type intro.txt
echo.
type starters.txt
echo.
set/p weapon=What Would You Like To Do?:
if %weapon%==Instructions goto INST
if %weapon%==instructions goto INST
if %weapon%==EXIT exit
if %weapon%==Katana goto STARTCONFIRM
if %weapon%==Pistol goto STARTCONFIRM
if %weapon%==Knife goto STARTCONFIRM
if %weapon%==A exit
if %weapon%==B exit
if %weapon%==C exit

:INST
cls
type inst.txt
echo.
set/p instreturn=What Would You Like To Do?:
if %instreturn%==return goto INTRO
if %instreturn%==leave exit

:STARTCONFIRM
cls
echo You have chosen the %weapon%!
set/p yousure=Are You OK With Your Choice (Y/N)?:
if %yousure%==Y goto NAME
if %yousure%==N goto INTRO

:NAME
cls
set/p name=What Is Your Name?:
if %name%== goto STARTG
echo %name%== >> player(s).txt

:STARTG
cls
type startg.txt
echo.
set/p search=What Are You Searching For? Your?:
if %search%== goto PART1
echo %search%== >> search.txt

:PART1
cls
echo That's what you were searching for, your %search%! How could you forget.
type part1.txt
echo.
set/p reaction1=Speak Or Walk-Past?:
if %reaction1%==Speak goto PART2A
if %reaction1%==speak goto PART2A
if %reaction1%==Walk-past goto PART2B
if %reaction1%==Walk-Past goto PART2B
if %reaction1%==walk-past goto PART2B
if %reaction1%==walk-Past goto PART2B

:PART2A
cls
type part2a.txt
echo.
set/p challenged=Do You Accept Or Decline This Challenge?:
if %challenged%==Y goto PART3A
if %challenged%==Accept goto PART3A
if %challenged%==N goto PART2B
if %challenged%==Decline goto PART2B

:PART2B
cls
type part2b.txt
echo.
set/p water=How Long Have You Gone Without Water?:
if %water%==1-day goto PART3B
if %water%==2-days goto PART3B
if %water%==3-days goto PART3B
if %water%==4-days goto PART3B
if %water%==5-days goto PART3B
if %water%==1-week goto PART3B

:PART3A
cls
type part3a.txt
echo.
set/p realitya=How Did This Happen?:
if %reailtya%==IDK goto PART4
if %reailtya%==Idk goto PART4
if %reailtya%==iDk goto PART4
if %reailtya%==idK goto PART4
if %reailtya%==idk goto PART4

:PART3B
cls
echo Wow, %water% is a pretty long time without water.
type part3b.txt
echo.
set/p reailtyb=How Did This Happen?:
if %reailtya%==IDK goto PART4
if %reailtya%==Idk goto PART4
if %reailtya%==iDk goto PART4
if %reailtya%==idK goto PART4
if %reailtya%==idk goto PART4

:PART4
cls
type part4.txt
echo.
set/p direction=What Direction Were You Headed?:
if %direction%==North goto PART5
if %direction%==north goto PART5
if %direction%==East goto PART5
if %direction%==east goto PART5
if %direction%==South goto PART5
if %direction%==south goto PART5
if %direction%==West goto PART5
if %direction%==west goto PART5


See More: Please help, is there something wrong somewhere?

Reply ↓  Report •

#1
April 18, 2017 at 02:18:18
You're asking a bit much for somebody to plow thriugh this 100+ line mess.
And I usually don't bother with any game stuff.
But since you said please...
Strip out all the type .txt echo. cls color title & other crap and I'll look at it.

While you're thinking about that, think about this:

You can avoid clutter like this:

if %weapon%==Katana goto STARTCONFIRM
if %weapon%==Pistol goto STARTCONFIRM
if %weapon%==Knife goto STARTCONFIRM

by using:

CALL :%weapon%

[CALL is usually better than GOTO]

2017-04-18 16:11:40.59 GMT +7

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#2
April 18, 2017 at 04:08:12
@echo off
title Test Game
:INTRO
echo Welcome to TBC by WackeyTech!
set/p weapon=What Would You Like To Do?:
if %weapon%==Instructions goto INST
if %weapon%==instructions goto INST
if %weapon%==EXIT exit
if %weapon%==Katana goto STARTCONFIRM
if %weapon%==Pistol goto STARTCONFIRM
if %weapon%==Knife goto STARTCONFIRM
if %weapon%==A exit
if %weapon%==B exit
if %weapon%==C exit
:INST
set/p instreturn=What Would You Like To Do?:
if %instreturn%==return goto INTRO
if %instreturn%==leave exit
:STARTCONFIRM
echo You have chosen the %weapon%!
set/p yousure=Are You OK With Your Choice (Y/N)?:
if %yousure%==Y goto NAME
if %yousure%==N goto INTRO
:NAME
set/p name=What Is Your Name?:
if %name%== goto STARTG
echo %name%== >> player(s).txt
:STARTG
set/p search=What Are You Searching For? Your?:
if %search%== goto PART1
echo %search%== >> search.txt
:PART1
echo That's what you were searching for, your %search%! How could you forget.
set/p reaction1=Speak Or Walk-Past?:
if %reaction1%==Speak goto PART2A
if %reaction1%==speak goto PART2A
if %reaction1%==Walk-past goto PART2B
if %reaction1%==Walk-Past goto PART2B
if %reaction1%==walk-past goto PART2B
if %reaction1%==walk-Past goto PART2B
:PART2A
set/p challenged=Do You Accept Or Decline This Challenge?:
if %challenged%==Y goto PART3A
if %challenged%==Accept goto PART3A
if %challenged%==N goto PART2B
if %challenged%==Decline goto PART2B
:PART2B
set/p water=How Long Have You Gone Without Water?:
if %water%==1-day goto PART3B
if %water%==2-days goto PART3B
if %water%==3-days goto PART3B
if %water%==4-days goto PART3B
if %water%==5-days goto PART3B
if %water%==1-week goto PART3B
:PART3A
set/p realitya=How Did This Happen?:
if %reailtya%==IDK goto PART4
if %reailtya%==Idk goto PART4
if %reailtya%==iDk goto PART4
if %reailtya%==idK goto PART4
if %reailtya%==idk goto PART4
:PART3B
echo Wow, %water% is a pretty long time without water.
set/p reailtyb=How Did This Happen?:
if %reailtya%==IDK goto PART4
if %reailtya%==Idk goto PART4
if %reailtya%==iDk goto PART4
if %reailtya%==idK goto PART4
if %reailtya%==idk goto PART4
:PART4
set/p direction=What Direction Were You Headed?:
if %direction%==North goto PART5
if %direction%==north goto PART5
if %direction%==East goto PART5
if %direction%==east goto PART5
if %direction%==South goto PART5
if %direction%==south goto PART5
if %direction%==West goto PART5
if %direction%==west goto PART5

Also could you please elaborate on the CALL command (I don't know if command is the right word). Did you mean it for me to replace the goto and say CALL :%weapon%
therefore moving the game to a label with the chosen weapon name? Or do i replace the if command entirely so that happens?

message edited by WackeyTech


Reply ↓  Report •

#3
May 1, 2017 at 07:07:42
✔ Best Answer
here ya go, updated it a bit & added a save/load function

@echo off&title Test Game&set health=100&set money=1000&set loadpoint=test1
:start
cls
echo [1] New game
echo [2] Continue
echo [3] Exit
choice /c 123 /n>nul
if %errorlevel% equ 1 goto NEWGAME
if %errorlevel% equ 2 goto LOADMENU
if %errorlevel% equ 3 exit /b
:NEWGAME
cls
echo ENTER name PLOx
set /p name=
if '%name%'=='' goto NEWGAME
if exist "%name%.txt" echo save already exists&pause>nul&goto start
goto INTRO
:SAVEMENU
(
echo %name%
echo %weapon%
echo %health%
echo %money%
echo %loadpoint%
)>%name%.txt
::etc
:LOADMENU
cls
echo Enter your last characters name:
set /p input=
if '%input%'=='' goto LOADMENU
if exist "%input%.txt" (
(
set /p name=%1
set /p weapon=%1
set /p health=%1
set /p money=%1
set /p loadpoint=%1
)<%input%.txt
)
goto %loadpoint%
::etc
:INTRO
cls
echo Welcome to TBC by WackeyTech!
echo.
echo [1] Instructions
echo [2] Exit
echo [3] Katana
echo [4] Pistol
echo [5] Knife
echo.
echo What Would You Like To Do %name%?:
choice /c 12345 /n>nul
if %errorlevel% equ 1 goto INST
if %errorlevel% equ 2 exit /b
if %errorlevel% equ 3 set weapon=Katana&goto STARTCONFIRM
if %errorlevel% equ 4 set weapon=Pistol&goto STARTCONFIRM
if %errorlevel% equ 5 set weapon=Knife&goto STARTCONFIRM
:INST
cls
echo [1] Return
echo [2] Exit
echo What Would You Like To Do?:
choice /c 12 /n>nul
if %errorlevel% equ 1 goto INTRO
if %errorlevel% equ 2 exit /b
:STARTCONFIRM
cls
echo You have chosen the %weapon%!
echo Are You OK With Your Choice (Y/N)?:
choice /c yn /n>nul
if %errorlevel% equ 1 goto NEXT
if %errorlevel% equ 2 goto INTRO
goto STARTCONFIRM
:NEXT
cls&echo saving...
set loadpoint=test1&goto SAVEMENU
:test1
cls
echo STATS:
echo.
echo name=%name%
echo weapon=%weapon%
echo health=%health%
echo money=%money%
echo loadpoint=%loadpoint%
echo.
echo Contunue from here&pause>nul&exit /b

Simple solutions are often the best


Reply ↓  Report •
Related Solutions


Ask Question