Since simply telling you that your title is no good doesn't add anything helpful, here is roughly what your code should look like (but also with an absurdly huge amount of comments so that you find out why I made the changes I did). Note that since everybody's programming style is different, "what it should look like" is somewhat relative.
Code: Select all
:: Everything with a :: at the start of the line is a comment. Some people will
:: tell you to use REM instead, and it's worth noting that if you want to
:: comment inside of a `for` loop, you absolutely HAVE to use REM, since :: is
:: technically a label and labels break `for` loops.
::
:: You'll also notice that none of the lines are longer than 80 characters. This
:: is considered "good programming practice" since you don't have to scroll
:: horizontally to read the entire comment.
::
:: Also, you may want to put some kind of header here to say what the script
:: does in case you put it away for six months and then find it again later.
:: For example,
::------------------------------------------------------------------------------
:: OFENKARTOFFLE ACCESS POINT
:: VERSION 0.1s
::
:: Provides an access point to Ofenkartoffle. Written by Blumekind.
::
:: USAGE: oap.bat
:: ARGUMENTS: None
:: RETURNS: None
::
:: VERSION HISTORY
:: ---------------
:: 0.1s (2016-04-27) - [ShadowThief] Super-commented version for learning
:: purposes
:: - [ShadowThief] Fixed errors
::
:: 0.1 (2016-04-27) - [Blumekind] Initial Version
::------------------------------------------------------------------------------
@echo off
title OFENKARTOFFLE ACCESS POINT VERSION 0.1
cls
echo Welcome to Ofenkartoffle's Access Point
:: I got rid of the pause because I felt that it didn't really add anything.
:: If you disagree, you can put it back.
:: Put double quotes around variables and values when setting them to preserve
:: spaces.
set /p "password=Please enter the correct password: "
:: The quotes are here in this case to prevent a syntax error in case the user
:: hit enter without entering anything; `if =="memes" goto :select` would break
:: the script, but `if ""=="memes" goto :select` acts correctly. You could
:: really use anything, but double quotes also prevents certain characters like
:: & and | from causing unintended behavior.
::
:: Also, I'm going to `:select` instead of `select` so that it would be more
:: consistent if your code had functions. At this point, it's just for looks.
if "%password%"=="memes" goto :select
:: This is the default action to do if the value of %password% is not memes
exit /b
:select
cls
:: I added dashes purely for aesthetic purposes. Feel free to remove them if you
:: don't like them; they don't do anything. Also, I added a Quit option so that
:: I don't have to click the red X when I'm done testing.
echo 1 - Residents
echo 2 - Public Facilities
echo 3 - Shops
echo 4 - Enemies
echo Q - Quit
:: I'm using choice instead of set so that it is impossible for the user to
:: enter an invalid option.
::
:: The /C option is used to give possible options, and numerical values are
:: assigned based on the order in which they are listed.
::
:: The /M option is used to show a message when asking for input.
::
:: The /N option is used to prevent the choice command from showing the
:: possible options to the user. I'm using this since we already showed them
:: the options earlier.
choice /C:1234Q /M "Welcome! Please choose an option! " /N
:: Errorlevel is a special system variable, similar to $? if you're familiar
:: with bash. If you're not, it's a variable that contains the exit value of
:: the last command that was performed (there are a few exceptions to this,
:: but that's out of scope for this explanation). The options are listed in
:: reverse order because batch considers `if errorlevel 1` to mean "if the
:: errorlevel is 1 or more," so if they were in the regular order and you
:: press 5 to quit, you would be sent to the Residents screen.
if errorlevel 5 exit /b
:: I changed the label names to make them more descriptive for people looking
:: at the code later (or for you six months from now).
if errorlevel 4 goto :show_enemies
if errorlevel 3 goto :show_shops
if errorlevel 2 goto :show_facilities
if errorlevel 1 goto :show_residents
:: I added a blank line above this line so that it is more obvious that this is
:: chunk of code is totally separate from the main code. If I wanted to, I could
:: also give it a header, like this:
::------------------------------------------------------------------------------
:: Shows the residents of the town/game/thing.
::
:: Arguments: None
:: Returns: None
::------------------------------------------------------------------------------
:: but you don't have to if you don't want to, since your code is just a bunch
:: of echo statements as of right now. If you do decide to add headers, it
:: doesn't have to look like that; that's just how I do them.
:show_residents
cls
:: I added a dash to both sides of your headers for aesthetic purposes.
echo -OFFICIALS-
echo Frostzauber - Assistant
echo Blumekind - Founder
echo Yeeehaww - Co-Founder
:: `echo.` prints a blank line. I'm printing blank lines for better readability.
:: Some people will tell you that you should use `echo/` instead, since `echo.`
:: can have unintended effects if there is a file called echo in your path or
:: current directory. These people will also tell you to use `echo(` instead of
:: `echo` for non-blank lines. It's up to you. I'm not doing it because I know
:: that I don't have any files called echo anywhere, but if you're going to
:: spread this file around online, it probably wouldn't hurt to make it a little
:: more bulletproof.
echo.
echo -REGULAR RESIDENTS-
echo None
:: I got rid of the "press any key to continue" message because `pause` already
:: shows one when you call it.
pause
goto :select
:: Another blank line since this is separate from the previous two code blocks.
:show_facilities
cls
echo -PUBLIC SHEEP PEN-
echo Sheep for free killing and shearing.
echo Rebreeding is a must.
echo Keep sheep under breedlimit.
echo If killing, please leave 2-4 sheep for rebreeding,
echo and use wheat for at least one baby.
echo.
echo -JAIL-
echo Used to report and record griefers and enemies.
echo Please report griefers at the front desk.
echo Griefers will be banned as soon as possible.
echo.
echo -CHICKEN COOP-
echo A small chicken coop used for public killing.
echo As with the sheep pen, please rebreed when killing.
echo Keep chickens under the breedlimit,
echo and make sure to leave at least 2 for rebreeding.
echo.
echo -WHEAT FARM-
echo A public wheat farm for the town.
echo Please replant.
pause
goto :select
:show_shops
cls
echo -SHOP INFORMATION-
echo A marketplace for player stands, used for selling knick-knacks and the like.
echo Restrictions apply, see signs at marketplace.
echo.
echo -SHOP OWNERS-
echo Yeeehaww - Public REDACTED
echo Blumekind - Monster Card Stand
echo RTP555 - Knick Knack Shop
pause
goto :select
:show_enemies
cls
echo -ENEMIES-
echo GOLDIELOL3 - Former town owner, possible threat.
echo TidgeyBoo - General cancer to the town, sure threat.
echo Neofox07 - Didn't join her nation, possible threat.
echo hollisterxo - Former town owner, possible threat.
echo.
echo -PRECAUTIONS-
echo Place wall around town.
echo Employ guards.
echo Claim all town chunks.
echo.
echo -IF GRIEFED-
echo Store records in jail.
echo Screenshot and report.
echo Investigate.
echo Do not accuse unless outnumbering.
echo Repair, up precaution measures.
echo.
echo -IF DECLARED WAR UPON-
echo Employ more guards.
echo Up propoganda.
echo Employ blacksmiths.
echo Make weapons.
echo Report any sliver of unfairness.
pause
:: I added a `goto :select` here because batch scripts always run from the top
:: down and when they run out of code, they end. Without this `goto`, the script
:: would end after you chose to view your enemies.
goto :select