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!
23 Comments
11 years ago on Step 3
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
Reply 4 years ago
:score (n)
set a/ qdone=%qdone%+2
It should be:
:score (n)
set /a qdone=%qdone%+1
echo Congratz, you have completed %qdone% question(s)!
The %qdone% shows how much the sum is.
So if the you see
qdone=2
you just need to add 1 to make it 3
Reply 11 years ago on Introduction
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
Reply 11 years ago on Introduction
By Q4 you wrote: set p/ input, That will NOT work you have to make it: set /p input.
Make the / before the p!
Reply 10 years ago on Introduction
Sorry, merely a mistype.
Reply 11 years ago on Step 3
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
5 years ago
Hey! I have biiig problem with the point system, I am using Windows 10 pro, and the command set not Works like yours. (When i will do command set a/ qdone=0 the placeholder in echo is %a/ qdone% and the if i will do set a/ qdone=%qdone%+1 it will display "0+1", well help me!!!
7 years ago
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
Reply 7 years ago
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.
7 years ago
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
8 years ago on Introduction
hope it works for you guys :D
8 years ago on Introduction
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
12 years ago on Step 3
It didnt work >:(
Reply 11 years ago on Introduction
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
Reply 12 years ago on Step 3
sorry it didn't work. Perhaps review your code?
11 years ago on Introduction
I'm currently making a trivia game with passwords and a help menu.
13 years ago on Step 3
People, plz rate nicely as this is MY FIRST instructable. Thanks!
Reply 12 years ago on Step 3
you have made batch awesome but do you think you could add a download
12 years ago on Introduction
You got a/ backwards.
I tried /a, and that worked instead of a/
so I think you got that backwards
13 years ago on Introduction
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...