Hi, I am new to batch scripting and was wondering if anyone could explain to me how to record an input. I want the script on input of answer to record whether it was right or wrong and how many answers the user got right and wrong. It is for a simple quiz game obviously
Does anyone know of any good beginner resources?
how to record answers in batch game
Moderator: DosItHelp
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: how to record answers in batch game
This may look complex for a total beginner, but it's definitely not. Study up!
Resources:
http://ss64.com/nt/syntax.html
http://ss64.com/nt/
Code: Select all
@echo off
set /p "variable=What's your input?: "
if /i "%variable%"=="answer" (echo:Correct.&set /a counter+=1) else echo:Incorrect.
echo:Number of questions correct: %counter%
Resources:
http://ss64.com/nt/syntax.html
http://ss64.com/nt/
Re: how to record answers in batch game
ill toy around with it, im trying to learn what it all means and how it is used.
I think i understand it a bit though. Ill let you know how it works
I think i understand it a bit though. Ill let you know how it works
Re: how to record answers in batch game
new2batch wrote:ill toy around with it, im trying to learn what it all means and how it is used.
I think i understand it a bit though. Ill let you know how it works
Ya, do what he said.
set var=dog
Sets the variable "var" to "dog". But
"set /p var=dog"
Sets var equal to whatever you type in, but it shows "dog" on the same line you have to type it in. So you'd want something like:
Code: Select all
@echo off
echo What was a famous historical war that could have been prevented if there wasn't a lack of communication?
set /p answer=The War of:
if "%answer%" EQU "1812" echo You are correct!
if "%answer%" NEQ "1812" echo You're an idiot...
pause
Re: how to record answers in batch game
I tried using the code that was added above for the counter and it didnt work. could it have something to do with the version of dos im using? ( using windows vista os )
Im confused on the arithmetic and counting functions. As a layperson its hard to decipher the lingo used. Anyone have any extremely simple program that illustrates these functions.
I ended up changing the script so it would just loop back to the question til the right input was entered, this is probably more valuable as a studying tool. However if anyone can help me understand it it would be most appreciated.
Im confused on the arithmetic and counting functions. As a layperson its hard to decipher the lingo used. Anyone have any extremely simple program that illustrates these functions.
I ended up changing the script so it would just loop back to the question til the right input was entered, this is probably more valuable as a studying tool. However if anyone can help me understand it it would be most appreciated.
Re: how to record answers in batch game
new2batch wrote:I tried using the code that was added above for the counter and it didnt work. could it have something to do with the version of dos im using? ( using windows vista os )
Im confused on the arithmetic and counting functions. As a layperson its hard to decipher the lingo used. Anyone have any extremely simple program that illustrates these functions.
I ended up changing the script so it would just loop back to the question til the right input was entered, this is probably more valuable as a studying tool. However if anyone can help me understand it it would be most appreciated.
No, it should work on all OS.
He's using a more professional way. Let me try and simplify it for you.
Code: Select all
@echo off
set counter=0
set /p variable=What's your input?:
if "%variable%" EQU "answer" (
echo Correct
set /a counter=%counter%+1
) else (
echo Incorrect.
)
set /p variable=What's your input?:
if "%variable%" EQU "answer" (
echo Correct
set /a counter=%counter%+1
) else (
echo Incorrect.
)
echo Number of questions correct: %counter%
pause
Try that. If you copy it correctly, it should work.