Introduction: Coding With Batch

Before we begin

Batch is a coding language made by Microsoft. It's insanely basic, in that it cannot display graphics, or play audio. Although, it is useful to open applications, make text-based games, and use as a to-the-second clock.

It's easy to learn, as there aren't many commands if you want to make something quick.

This tutorial will explain a few basic commands, along with a tutorial of how to make a clock.

Note: Batch only works on windows systems from the DOS days, to the most recent version of Windows. So don't try on Unix based systems (Linux, android...) or MacOS's (iOS, Mackintosh).


WHEN SAVING A BATCH FILE MAKE SURE IT ENDS WITH ".bat" OR ".cmd" (Personally, I prefer .bat)

Also, if you want to edit it, you can right click > Edit, to edit the file to open in Notepad. If you use something else, like Sublime Text, or Notepad++, you can usually go to File > Open... and find the file there, if it is not already loaded.

(For Notepad++ users, you can right click > Edit with Notepad++ for ease of use.)

(Sorry for low-resolution image. Needed an image so said "This will do" and put it there.)

Step 1: The Basics | Echo

Some commands will be constant in everything you do.

The first of these will be "echo".

What does echo do?

Essentially, it relays all text you input. for example, if you put "echo Hello!" into the command prompt, you'll get "Hello!" as an output.

Echo can also be turned off.

This is done simply by going "@echo off". This stops it from relaying information like"C:\windows\System32 (if you're running it in administrator mode).

Step 2: Step 2: the Basics | Color and Cls

Color is self explanatory. It allows you to change the font color and background color of the terminal window. A more detailed explanation can be found by typing "color ?" into a command prompt (cmd.exe)

Cls is shorthand for "Clear Screen". It wipes the screen of all the previously input data, such as entered commands, text, and so on.

Step 3: Step 3: the Basics | "%%", ":" and Goto

This is where things get interesting.

With "%%", you are able to save some data, such as entered text or other stats until the console is cleared (closed), useful in some scripts. (In text-based games, you can use this to save names, stats, and whatever else can be altered and tracked.)

With ":" and goto, you can create loops, and move around a script. So, you could have a user input something, then have the script exit or go back to the start.

Step 4: Step 4: the Basics | Finale

There's a few other things you should note before going on.

set /p insertsomethinghere=Enter text:

if %insertsomethinghere%==1 goto aplacetogo

This can be used as a multiple choice selection option. Input a certain response, and be lead to a different answer.


{ set /p insertaname=Please input a name:

if %insertaname%==%insertaname% goto nextstep }

This will continue to move onto the next step, whatever that may be.

Note: Everything in bold on this page isn't required. Everything in those fields will be different. Everything underlined can be copied as many times as needed.

Special note: in between the {} brackets, this is technically all you need. Although you could have a specific name that gives you special benefits, characters recognize you, or you have an alternative path. all you need to do is add "if %insertaname%==Bob goto nextstepbob" (you will need to add a different path which may be annoying, or just put a small alternative path, that, will link back up with the main one eventually.)

Step 5: Step 5: Some Fun | a Clock.

This is something I learned first, actually.

@echo off

color 0a



echo The current time is %time% and the date is %date%

goto clock

Optionally, you could put "cls" after the :clock

Although this will cause it to flicker and is a little annoying.

Remember to properly save!

Step 6: Step 6: Eventually...

Currently, I've been working on a game. Below is what I currently have.

It's basic, and can be played somewhat, although not even close to what I want to do.

(Due to how it decides to format the text, I'll provide it if there is a request.)

Step 7: Extra Help

Feel free to ask if you get stuck on something. I will try to help as soon as I can.

Thanks for reading, and hopefully this helps.