Introduction: 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.


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.


Step 2: Making a Score System


@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


This should be your script so far.
Ok, lets get into some explanation.

1. What is set /p?
Ok, in simpler terms, is kind of like setting up a question.

2. If? What is 'if'?
'If' checks a condition. So 'if' the input is a, it will transport you to the label 'a'. Getting it so far?

3. What's with the percentage marks?
If a word is surrounded with these percentage marks, then that means it is a variable.

Now, this step I am going to explain how to make a score system. A bit tricky to the novice scripter.

Firstly, we shall use a 'set a/'

set a/

Then we shall type in a bit more to the 'set /a', as shown below. The score we will set is how many questions done. This will be abbreiviated to 'qdone'

set a/ qdone=0

Pretty simple. Next, I will show you how to add points to the 'qdone'. We shall use two labels. The first label is the question.

:Q1
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

Ok, thats basically it. Let's get into explanation.

1.How does the set a/ qdone=%qdone%+1 work?
Well, its like resetting the variable, except adding 1 more point.

2. What is the bold for, on the goto error?
Well, i'd just like to point it out.If the command that was entered is invalid, it will go to the error label (that you will make)







Step 3: Finalizing

@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 Q1
if %input%==b goto instructions
goto error

Ok, back to the main menu. We will now add the extra labels that are required (error, instructions, wrong)

@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
goto error

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

:instructions
echo Type instructions here
pause
goto Main

:wrong
echo Sorry, but...
echo YOU LOSE!!
pause
goto Main

:Q1
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
(Put question here)

Okay, thats basically it. Now, this step is UBER IMPORTANT
save it as a BAT file, so say your game is called trivia save it as trivia.bat





That's basically it! Add more questions, and a winning screen, and your done!



Comments

author
XxLunaHowlingHowlsA made it! (author)2016-01-30

Why does this not work?

@echo off

echo what is your name?

set /p name=

echo Hello %name%

goto level1

:level1

echo elsa a boy

echo A) True

echo B) False

if %select% == goto wrong

if %select% == goto bye bye

:worong

you were wrong! sorry!

pause

exit

:bye bye

echo goodbye you were right!

pause

exit

author
bobbym46 made it! (author)bobbym462016-05-13

The reason why it wont work is because 1. wrong is misspelled 12th line on the code (technically 13 because of your comment but since were talking about the code 12th line.) And also

if %select% == goto wrong

if %select% == goto bye bye

this code is wrong it should be

if %select% == A goto wrong

if %select% == B goto bye bye

And to avoid people cheating I would put this command in after it 'Goto Cheater' this is to prevent people from typing random things and they get it right. I hope I helped you.

author
CoderCreator made it! (author)2015-12-06

You can actually do

:FamilyGuyQuestion1

cls

Title Family Guy

echo.

echo Who is the main character in Family Guy?

echo.

echo Peter

echo.

echo Glenn

echo.

echo Joe

echo.

set /p familyguy1=Enter:

if %familyguy1% equ Peter goto CorrectFG1

if %familyguy1% equ Glenn goto IncorrectFG1

if %familyguy1% equ Joe goto IncorrectFG1

goto FamilyGuyQuestion1

Something Like this instead of using numbers for answers, works for menus too

author
Cooler Reyes made it! (author)2015-05-23

hope it works for you guys :D

author
Cooler Reyes made it! (author)2015-05-23

well i made my own one.. but its sure a good one..

@echo off

title Cooler Reyes Mini Game

echo Welcome :D

pause

echo Would you like me to start the game? (y/n)

set /p c=

if %c%==y goto menu32

if %c%==n exit

:menu32

cls

echo Hi! im Dexter, how about you?

set /p name=

cls

echo Nice to meet you %name%!

pause

cls

echo What minigame do you want to play %name%?

echo Math or Bignumber?

set /p select=

if %select%==Math goto mathquiz

if %select%==Bignumber goto number

:mathquiz

cls

echo You have chosen math %name%!

pause

echo Now you'll suffer!

pause

cls

echo ok, first one :D

pause

echo 365+546?

echo 1. 779

echo 2. 911

echo 3. 690

set /p choice1=

if %choice1%==1 goto lose1

if %choice1%==2 echo You got me!

if %choice1%==3 goto lose1

pause

cls

echo now, more difficult XD

pause

echo 650+765?

echo 1. 1334

echo 2. 1565

echo 3. 1415

set /p choice2=

if %choice2%==1 goto lose2

if %choice2%==2 goto lose2

if %choice2%==3 echo wooooow!

pause

cls

echo your really good at this %name%!

pause

echo but not this time!

pause

echo 924+876?

echo 1. 2000

echo 2. 1900

echo 3. 1800

set /p choice3=

if %choice3%==1 echo You won the game!! congrats %name% :D

if %choice3%==2 goto lose3

if %choice3%==3 goto lose3

cls

:lose1

cls

echo haha, you lose :D

pause

echo try again? (y/n)

set /p kj=

if %kj%==y goto mathquiz

if %kj%==n exit

cls

:lose2

cls

echo haha, you lose :D

pause

echo try again? (y/n)

set /p kj=

if %kj%==y goto mathquiz

if %kj%==n exit

cls

:lose3

cls

echo haha, you lose :D

pause

echo try again? (y/n)

set /p kj=

if %kj%==y goto mathquiz

if %kj%==n exit

cls

:number1

cls

echo ok lets play the thing you selected %name%! Big number!!!

pause

echo type set to go to settings

set /p sets=

if %sets%==set goto settings

echo choose a number 1-10

set /p cnumber=

if %cnumber%==1 echo i choose 2! I Win! Play Again? (y/n)

set /p yorno=

if %cnumber%==2 echo i choose 3! I Win! Play Again? (y/n)

if %cnumber%==3 echo i choose 4! I Win! Play Again? (y/n)

if %cnumber%==4 echo i choose 5! I Win! Play Again? (y/n)

if %cnumber%==5 echo i choose 6! I Win! Play Again? (y/n)

if %cnumber%==6 echo i choose 7! I Win! Play Again? (y/n)

if %cnumber%==7 echo i choose 8! I Win! Play Again? (y/n)

if %cnumber%==8 echo i choose 9! I Win! Play Again? (y/n)

if %cnumber%==9 echo i choose 10! I Win! Play Again? (y/n)

if %cnumber%==10 echo i choose 10! Tie! Play Again? (y/n)

if %yorno%==y goto number

if %yorno%==n exit

cls

:settings

cls

echo CHOOSE :D

pause

echo 1. I want me to always win

echo 2. I want me to always lose

set /p sets1=

if %sets1%==1 goto number2

if %sets1%==2 goto number1

cls

:number 2

cls

echo ok lets play the thing you selected %name%! Big number!!!

pause

echo type set to go to settings

set /p sets=

if %sets%==set goto settings

echo choose a number 1-10

set /p cnumber=

if %cnumber2%==1 echo i choose 1! Tie! Play Again? (y/n)

set /p yorno2=

if %cnumber2%==2 echo i choose 1! You Win! Play Again? (y/n)

if %cnumber2%==3 echo i choose 2! You Win! Play Again? (y/n)

if %cnumber2%==4 echo i choose 3! You Win! Play Again? (y/n)

if %cnumber2%==5 echo i choose 4! You Win! Play Again? (y/n)

if %cnumber2%==6 echo i choose 5! You Win! Play Again? (y/n)

if %cnumber2%==7 echo i choose 6! You Win! Play Again? (y/n)

if %cnumber2%==8 echo i choose 7! You win! Play Again? (y/n)

if %cnumber2%==9 echo i choose 8! You win! Play Again? (y/n)

if %cnumber2%==10 echo i choose 9! You win! Play Again? (y/n)

if %yorno2%==y goto number

if %yorno2%==n exit

author
MiningPotatoes made it! (author)2012-02-16

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

author
Prof. Pickle made it! (author)Prof. Pickle2012-08-08

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




author
jayfin made it! (author)jayfin2012-08-18

By Q4 you wrote: set p/ input, That will NOT work you have to make it: set /p input.
Make the / before the p!

author
Prof. Pickle made it! (author)Prof. Pickle2012-12-22

Sorry, merely a mistype.

author
jayfin made it! (author)jayfin2012-08-18

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

author
TheExplodingTacoz made it! (author)2011-07-15

It didnt work >:(

author
thillryan made it! (author)thillryan2011-12-29

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

author
Mistersalt made it! (author)Mistersalt2011-08-06

sorry it didn't work. Perhaps review your code?

author
Ca$hews made it! (author)2011-10-12

I'm currently making a trivia game with passwords and a help menu.

author
Mistersalt made it! (author)2010-06-27

People, plz rate nicely as this is MY FIRST instructable. Thanks!

author
thegriffy100 made it! (author)thegriffy1002011-05-26

you have made batch awesome but do you think you could add a download

author
daniel951 made it! (author)2011-01-28

You got a/ backwards.
I tried /a, and that worked instead of a/
so I think you got that backwards

author
quengilar made it! (author)2010-09-03

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...

author
Mistersalt made it! (author)Mistersalt2010-09-13

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

author
quengilar made it! (author)quengilar2010-09-13

Thanks man, i kept doing this and was like WTF it just closes this helps a lot!

author
Mistersalt made it! (author)Mistersalt2010-09-18

No problamo! I'm here to help if you need any other assistance.

About This Instructable

15,324views

7favorites

License:

More by Mistersalt:How to make a simple Batch game (trivia!)
Add instructable to: