Need help with some batch.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Zixizx
Posts: 2
Joined: 01 Aug 2010 11:44

Need help with some batch.

#1 Post by Zixizx » 01 Aug 2010 11:52

Hello i have decided to give batch a go buy making a text advenutre but i need some help as i havent coded in batch before im not very good i got basic commands like "echo" "pause" and "set /p udefine=" but i am haveing trouble with ym text adventure here is the link to the paste bin wiht ym code in http://pastebin.com/cdqXCvjG


thanks for your help Zixizx

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help with some batch.

#2 Post by aGerman » 01 Aug 2010 13:04

You should not write this kind of spaghetti code. Call subroutines instead.
Have a look at that

Code: Select all

@echo off
color 0f
title An Adventure Through Text
:top
cls
echo ***************************************************************
echo.
echo Your Adventure Begines Here.
echo.
echo ***************************************************************
echo.
echo You Have Started Your Adventure What Would You Like to Do?

:MainLoop
echo [1] Go To The Pub.
echo [2] Go To The Woods.
echo [3] Go Home.
echo.
echo [e] Exit
echo.
echo ***************************************************************
echo Enter The Number Of The Action You Wish To Choose.
echo.
set "udefine="
set /p udefine=
echo.
echo ***************************************************************
if "%udefine%"=="1" call :pub
if "%udefine%"=="2" call :woods
if "%udefine%"=="3" call :home
if /i "%udefine%"=="e" goto :eof
goto MainLoop

:pub
cls
echo You Go To The Pub.
echo.
echo You Buy A Drink And Have A Meal You Feel Refreshed.
pause
cls
goto :eof

:woods
cls
echo You Enter The Woods And You Find Some Gold,
echo You Take It Back To The Town,
echo And earn your Riches.
pause
cls
echo *****************************
echo You Have Returned To The Town Center
echo What Would You Like to Do?
echo.
goto :eof

:home
cls
echo *****************************
echo You're at home now
echo What Would You Like to Do?
echo.
goto :eof


In main: By goto :eof it jums to the end of file and ends the batch
In subroutines: By goto :eof it jumps back to the point where the subroutine was called.

Hope that helps
aGerman

Zixizx
Posts: 2
Joined: 01 Aug 2010 11:44

Re: Need help with some batch.

#3 Post by Zixizx » 01 Aug 2010 14:02

You my freind are a ledgend thank you so much :D

Post Reply