Instructables
Picture of How to make a simple Batch game (trivia!)

HI
Today i'm gonna show you how to make a trivia game with Batch. Since batch is kind of limited, some awesome features that you may be thinking of may not come true. That's just how it goes. Hopefully my steps, to you, are simple and easy to understand.


 
Remove these adsRemove these ads by Signing Up

Step 1: Making the main page


Ok, like all games, they have a main page(menu). Use all your text pictures-making skills and make it nice and beautiful. Ok, for those who have not much skill in this batch script, input this code:

Firstly, start with a @echo off (duh)

@echo off

Then, add a title

@echo off
title The Trivia Game

Now, add the main title(that will be shown on the screen) and a label

@echo off
title The Trivia game
:Main
echo.
echo.
echo                          ------------------------------
echo                              Trivia Game
echo                         --------------------------------
echo.
echo.

Your script should now look like this^

Now, add the selection part. This is slightly trickier


@echo off
title The Trivia game
:Main
echo.
echo.
echo                ------------------------------
echo                    Trivia Game
echo              --------------------------------
echo.
echo.
echo                     ------------------
echo                    Type A and press ENTER to play
echo                    Type B and press ENTER to see instructions
echo                    ----------------------
set /p input=COMMAND?
if %input%==a goto PLAY
if %input%==b goto instructions

You will use the selection code you used here for all the questions.
Ok, thats basically it for this step.


This is my code. It won't work, for some reason.
Please reply.
Sorry bout the spacing

@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=COMMAND?
if %input%==a goto start
if %input%==b goto instructions
goto error

:error
echo Dingbat! Thats an invalid command.
pause
goto Main

:instructions
echo This is a trivia game. Just do what you think you need to do.
pause
goto Main

:wrong
echo Sorry, but...
echo YOU LOSE!!
echo Now start over. You deserve another chance!
pause
goto Main

:start
echo ----------------------------------------
echo What is a boat?
echo ----------------------------------------
echo [a-A water vehichle] [b-A land vehicle]
echo [c-A truck] [d-An animal]
set p/ input=ANSWER?
if %input%==a goto score1
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 1
set a/ qdone=%qdone%+1
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q2

:Q2
echo --------------------------------
echo What is a duck?
echo --------------------------------
echo [a- THE BEST ANIMAL EVAR] [b- An ordinary animal]
echo [c- A vegetable] [d-Something random]
set p/ input=ANSWER?
if %input%==a goto score2
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 2
set a/ qdone=%qdone%+2
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q3

:Q3
echo ----------------------------------
echo How do you make a cake?
echo -----------------------------------
echo [a-Using the power of your MIND]
echo [b- Using a recipe]
echo [c- Go buy it] [d- Get your friends to make it for you]
set p/ input=ANSWER?
if %input%==a goto wrong
if %input%==b goto score3
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 3
set a/ qdone=%qdone%+3
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q4

:Q4
echo ------------------------------------
echo 5 cubed= ?
echo ----------------------------------
echo [a-15] [b-125] [c-250] [d-500]
set p/ input=ANSWER?
if %input%==a goto wrong
if %input%==b goto score4
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 3
set a/ qdone=%qdone%+4
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q5

:Q5
echo --------------------------------------------
echo What file format does this game use?
echo --------------------------------------------
echo [a- .cmd] [b- .exe] [c- I don't even know] [d- .bat]
set p/ input=ANSWER?
if %input%==a goto wrong
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto winner
goto error

:winner
echo Great job! You beat the trivia game!
echo If you'd like, email this to your friends!
echo Be sure to inform them that it can only be used on Windows PC's.
echo Thanks for playing!!!!
pause
There are some errors in the coding

I fixed them and this is the new one:

@echo off
title The Trivia game
:Main
echo.
echo.
echo ------------------------------
echo Trivia Game
echo --------------------------------
echo.
echo.
echo ------------------
echo Type A and press ENTER to play
echo Type B and press ENTER to see instructions
echo ----------------------
set /p input=
if %input%==a goto start
if %input%==b goto instructions
if %inpu%==A goto start
if %input%--B goto instructions
goto error

:error
echo Dingbat! Thats an invalid command.
pause
goto Main

:instructions
echo This is a trivia game. Just do what you think you need to do.
pause
goto Main

:wrong
echo Sorry, but...
echo YOU LOSE!!
echo Now start over. You deserve another chance!
pause
goto Main

:start
echo ----------------------------------------
echo What is a boat?
echo ----------------------------------------
echo [a-A water vehichle] [b-A land vehicle]
echo [c-A truck] [d-An animal]
set p/ input=ANSWER?
if %input%==a goto score1
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 1
set a/ qdone=%qdone%+1
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q2

:Q2
echo --------------------------------
echo What is a duck?
echo --------------------------------
echo [a- THE BEST ANIMAL EVAR] [b- An ordinary animal]
echo [c- A vegetable] [d-Something random]
set p/ input=ANSWER?
if %input%==a goto score2
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 2
set a/ qdone=%qdone%+2
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q3

:Q3
echo ----------------------------------
echo How do you make a cake?
echo -----------------------------------
echo [a-Using the power of your MIND]
echo [b- Using a recipe]
echo [c- Go buy it] [d- Get your friends to make it for you]
set p/ input=ANSWER?
if %input%==a goto wrong
if %input%==b goto score3
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 3
set a/ qdone=%qdone%+3
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q4

:Q4
echo ------------------------------------
echo 5 cubed= ?
echo ----------------------------------
echo [a-15] [b-125] [c-250] [d-500]
set p/ input=ANSWER?
if %input%==a goto wrong
if %input%==b goto score4
if %input%==c goto wrong
if %input%==d goto wrong
goto error

:score 3
set a/ qdone=%qdone%+4
echo Congratz, you have completed %qdone% question(s)!
echo Press any button to go to the next question!
pause>nul
goto Q5

:Q5
echo --------------------------------------------
echo What file format does this game use?
echo --------------------------------------------
echo [a- .cmd] [b- .exe] [c- I don't even know] [d- .bat]
set p/ input=ANSWER?
if %input%==a goto wrong
if %input%==b goto wrong
if %input%==c goto wrong
if %input%==d goto winner
goto error

:winner
echo Great job! You beat the trivia game!
echo If you'd like, email this to your friends!
echo Be sure to inform them that it can only be used on Windows PC's.
echo Thanks for playing!!!!
pause




By Q4 you wrote: set p/ input, That will NOT work you have to make it: set /p input.
Make the / before the p!
Sorry, merely a mistype.
I tried all of the trivia batch files on this page and none of them worked, so I came up with my own. I tested it out like a million times so I know it works.
Save as a batch file (.bat).

color a4
@echo off
title Trivia game
:Main
set /p choice=Type A and press ENTER to play. Type B and press ENTER for instructions. Type C and press ENTER for credits.
if %choice%==a goto start
if %choice%==b goto instructions
if %choice%==c goto credits

:instructions
echo Instructions: Type the letter of the answer you think is correct.
goto main

:credits
echo Credits: This game was made by JAYFIN programing
goto main

:start
@echo off
set /p choice=What food group has the highest levels of proteint? 1: Bread, 2:Vegetables, 3:Meat, 4:Fruit
if %choice%==1 goto wrong
if %choice%==2 goto wrong
if %choice%==3 goto correct
if %choice%==4 goto wrong
echo That answer is unacceptable. Try again.
goto start

:wrong
echo Wrong answer try again.
goto start

:correct
echo Answer correct.
goto Q2

:Q2
@echo off
set /p choice=Who said: "I'm the president of the United States and I'm not going to eat any more broccoli"? 1:George H. W. Bush, 2:Bill Clinton, 3:Barak Obama, 4:Ronald Reagan.
if %choice%==1 goto correct q2
if %choice%==2 goto wrong q2
if %choice%==3 goto wrong q2
if %choice%==4 goto wrong q2
echo That answer is unacceptable. Try again.
goto Q2

:wrong q2
echo Wrong answer try again.
goto Q2

:correct q2
echo Answer correct.
goto Q3

:Q3
@echo off
set /p choice=In Peter Pan, what sort of creature was Nana? 1:Dog, 2:Human, 3:Firefly, 4:Fairy.
if %choice%==1 goto correct q3
if %choice%==2 goto wrong q3
if %choice%==3 goto wrong q3
if %choice%==4 goto wrong q3
echo That answer is unacceptable. Try again.
goto Q3

:wrong q3
echo Wrong answer try again.
goto Q3

:correct q3
echo Answer correct.
goto Q4

:Q4
@echo off
set /p choice=What's the name of the bird that Sylvester (from loony tunes) chases in vain? 1:Cupcake, 2:Tweety Pie, 3:Jerry, 4:Eli.
if %choice%==1 goto wrong q4
if %choice%==2 goto correct q4
if %choice%==3 goto wrong q4
if %choice%==4 goto wrong q4
echo That answer is unacceptable. Try again.
goto Q4

:wrong q4
echo Wrong answer try again.
goto Q4

:correct q4
echo Answer is correct.
goto Q5

:Q5
@echo off
set /p choice=Where was the second Atom bomb dropped? 1:Tokyo, 2:Osaka, 3:Hiroshima, 4:Nagasaki.
if %choice%==1 goto wrong q5
if %choice%==2 goto wrong q5
if %choice%==3 goto wrong q5
if %choice%==4 goto correct q5
echo That answer is unacceptable. Try again.
goto Q5

:wrong q5
echo Wrong answer try again.
goto Q5

:correct q5
echo Congratulations! You have completed this quiz.
echo JAYFIN Programing
goto Main
It didnt work >:(
Did you at the places for the code to got

Ex:
@echo off
:start
echo enter a number
set /p num=(1-3)
if %num% == 1 goto num1
if %num% == 2 goto num2
if %num% == 3 goto num3
:num1
echo you entered the number1
pause
goto start
:num2
echo you entered the number2
pause
goto start
:num2
echo you entered the number2
pause
goto start
Mistersalt (author)  TheExplodingTacoz3 years ago
sorry it didn't work. Perhaps review your code?
Ca$hews3 years ago
I'm currently making a trivia game with passwords and a help menu.
Mistersalt (author) 4 years ago
People, plz rate nicely as this is MY FIRST instructable. Thanks!
you have made batch awesome but do you think you could add a download
daniel9513 years ago
You got a/ backwards.
I tried /a, and that worked instead of a/
so I think you got that backwards
quengilar4 years ago
I'm trying to get this to work, when you have the command "if %input%==a goto PLAY" where is play? It just closes my window...
Mistersalt (author)  quengilar4 years ago
Oh sorry, i must have forgot to put that in. Well, you can create a :play label otherwise you can just change the script so that...

if %input%==a goto Q1

By the way, if there is a label that does not exist in the script, then it just closes it

Woops XD
Thanks man, i kept doing this and was like WTF it just closes this helps a lot!
Mistersalt (author)  quengilar4 years ago
No problamo! I'm here to help if you need any other assistance.