I'm new to batch and am mainly using it for this one school project. I'm also new to stack overflow, so leniency of mistakes would be appreciated. I keep getting the error message "set/a was unexpected at this time" when I get to ":MARK" in the code. I'm just going to dump the entire code here, sorry if it's confusing.
#echo off
color 7C
:MAINMENU
cls
title Main Menu
echo To start the quiz, type 1
echo To view the accreditations, type 2
echo To exit the Shop Quiz, type 3
set/p menuselection= Make your selection:
if %menuselection%==1 goto QUESTIONONE
if %menuselection%==2 goto ACCREDITATION
if %menuselection%==3 goto ENDPROGRAM
:QUESTIONONE
cls
title Question One of Ten
echo What do you do if there is an accident in the shop?
echo.
echo 1. Duck and cover your head to avoid injury
echo 2. Immediately go tell the instructor
echo 3. Walk it off
echo 4. Help the person who got hurt and fix the problem
echo.
set/p aone=
goto QUESTIONTWO
:QUESTIONTWO
cls
title Question Two of Ten
echo What attitude should you always have in the shop?
echo.
echo 1. Calm and careful
echo 2. Focused on surroundings
echo 3. Mischievous and goofy
echo 4. Attentive and ready to avoid injury
echo.
set/p atwo=
goto QUESTIONTHREE
:QUESTIONTHREE
cls
title Question Three of Ten
echo Which of the following is NOT allowed for dress in shop?
echo.
echo 1. Sandals
echo 2. Tucked Loose clothing
echo 3. Crocs
echo 4. Eye Goggles
echo.
set/p athree=
goto QUESTIONFOUR
:QUESTIONFOUR
cls
title Question Four of Ten
echo What list of items must you be able to locate in the shop?
echo.
echo 1. Wood, tool shelf, eye goggles, fire extinguishers, power buttons
echo 2. Fire blankets, first aid kits, fire extinguishers, power buttons, eye goggles
echo 3. Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons
echo 4. Eye goggles, fire blankets, tool shelf, fire extinguishers, power buttons
echo.
set/p afour=
goto QUESTIONFIVE
:QUESTIONFIVE
cls
title Question Five of Ten
echo Which of these potential risks is caused by clutter and spills?
echo.
echo 1. Bumping into things
echo 2. Unnecessary strain
echo 3. The drill catching the stock and spinning it
echo 4. Prevention of proper lifting techniques
echo.
set/p afive=
goto QUESTIONSIX
:QUESTIONSIX
cls
title Question Six of Ten
echo Which of these IS an acceptable mental condition for shop work?
echo.
echo 1. Tired
echo 2. Hesitant
echo 3. Rushed
echo 4. Under the influence
echo.
set/p asix=
goto QUESTIONSEVEN
:QUESTIONSEVEN
cls
title Question Seven of Ten
echo Your work station should NOT be:
echo.
echo 1. Adequately ventilated
echo 2. Well-organized
echo 3. Compact
echo 4. Well-lit
echo.
set/p aseven=
goto QUESTIONEIGHT
:QUESTIONEIGHT
cls
title Question Eight of Ten
echo What tool should you use to secure your work?
echo.
echo 1. Wrench
echo 2. Paper weight
echo 3. Vice
echo 4. Your hand
echo.
set/p aeight=
goto QUESTIONNINE
:QUESTIONNINE
cls
title Question Nine of Ten
echo What can you use to hold onto things like nails, screws, or chisels?
echo.
echo 1. Pocket
echo 2. Hands
echo 3. Mouth
echo 4. All of the above
echo.
set/p anine=
goto QUESTIONTEN
:QUESTIONTEN
cls
title Question Ten of Ten
echo Of the following only one action is acceptable. Select it.
echo.
echo 1. Using files without handles
echo 2. Prying with a chisel
echo 3. Using clamps that are really big
echo 4. Hammering with a wrench
echo.
set/p athree=
goto RESULTS
:RESULTS
cls
title Results
goto MARK
:RESULTONE
echo Question one of ten
echo What do you do if there is an accident in the shop?
if %aone%==1 echo "Duck and cover your head to avoid injury" is wrong.
if %aone%==1 echo Correct answer is 2, "Immediately go tell the instructor"
if %aone%==2 echo "Immediately go tell the instructor" is correct.
if %aone%==3 echo "Walk it off" is wrong.
if %aone%==3 echo Correct answer is 2, "Immediately go tell the instructor"
if %aone%==4 echo "Help the person who got hurt and fix the problem" is wrong.
if %aone%==4 echo Correct answer is 2, "Immediately go tell the instructor"
pause
goto RESULTTWO
:RESULTTWO
echo Question two of ten
echo What attitude should you always have in shop?
if %atwo%==1 echo "Calm and careful" is correct.
if %atwo%==2 echo "Focused on surroungings" is wrong.
if %atwo%==2 echo Correct answer is 1, "Calm and careful"
if %atwo%==3 echo "Mischievous" is wrong.
if %atwo%==3 echo Correct answer is 1, "Calm and careful"
if %atwo%==4 echo "Attentive and ready to avoid" is wrong.
if %atwo%==4 echo Correct answer is 1, "Calm and careful"
pause
goto RESULTTHREE
:RESULTTHREE
echo Question three of ten
echo Which of the following is NOT allowed for dress in shop?
if %athree%==1 echo "Sandals" is correct.
if %athree%==2 echo "Tucked loose clothing" is wrong.
if %athree%==2 echo Correct answer is 1, "Sandals"
if %athree%==3 echo "Crocs" is wrong.
if %athree%==3 echo Correct answer is 1, "Sandals"
if %athree%==4 echo "Eye goggles" is wrong.
if %athree%==4 echo Correct answer is 1, "Sandals"
pause
goto RESULTFOUR
:RESULTFOUR
echo Question four of ten
echo What list of items must you be able to locate in the shop?
if %afour%==1 echo "Wood, tool shelf, eye goggles, fire extinguishers, power buttons" is wrong.
if %afour%==1 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons"
if %afour%==2 echo "Fire blankets, first aid kits, fire extinguishers, power buttons" is wrong.
if %afour%==2 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons"
if %afour%==3 echo "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons" is correct.
if %afour%==4 echo "Eye goggles, fire blankets, tool shelf, fire extinguishers, power buttons" is wrong.
if %afour%==4 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons"
pause
goto RESULTFIVE
:RESULTFIVE
echo Question five of ten
echo Which of these potential risks is caused by clutter and spills
if %afive%==1 echo "Bumping into things" is correct.
if %afive%==2 echo "Unnecessary strain" is wrong.
if %afive%==2 echo Correct answer is 1, "Bumping into things"
if %afive%==3 echo "The drill catching the stock and spinning it" is wrong.
if %afive%==3 echo Correct answer is 1, "Bumping into things"
if %afive%==4 echo "Prevention of proper lifting techniques" is wrong.
if %afive%==4 echo Correct answer is 1, "Bumping into things"
pause
goto RESULTSIX
:RESULTSIX
echo Question six of ten
echo Which of these is an acceptable mental condition for shop work?
if %asix%==1 echo "Tired" is wrong.
if %asix%==1 echo Correct answer is 2, "Hesitant"
if %asix%==2 echo "Hesitant" is correct.
if %asix%==3 echo "Rushed" is wrong.
if %asix%==3 echo Correct answer is 2, "Hesitant"
if %asix%==4 echo "Under the influence" is wrong.
if %asix%==4 echo Correct answer is 2, "Hesitant"
pause
goto RESULTSEVEN
:RESULTSEVEN
echo Question seven of ten
echo Your work station should NOT be:
if %aseven%==1 echo "Adequately ventilated" is wrong.
if %aseven%==1 echo Correct answer is 3, "Compact"
if %aseven%==2 echo "Well-organized" is wrong.
if %aseven%==2 echo Correct answer is 3, "Compact"
if %aseven%==3 echo "Compact" is correct.
if %aseven%==4 echo "Well-lit" is wrong.
if %aseven%==4 echo Correct answer is 3, "Compact"
pause
goto RESULTEIGHT
:RESULTEIGHT
echo Question eight of ten
echo What tool should you use to secure your work?
if %aeight%==1 echo "Wrench" is wrong.
if %aeight%==1 echo Correct answer is 3, "Vice"
if %aeight%==2 echo "Paper weight" is wrong.
if %aeight%==2 echo Correct answer is 3, "Vice"
if %aeight%==3 echo "Vice" is correct.
if %aeight%==4 echo "Your hand" is wrong.
if %aeight%==4 echo Correct answer is 3, "Vice"
pause
goto RESULTNINE
:RESULTNINE
echo Question nine of ten
echo What can you use to hold onto things like nails, screws, or chisels?
if %anine%==1 echo "Pocket" is wrong.
if %anine%==1 echo Correct answer is 2, "Hands"
if %anine%==2 echo "Hands" is correct.
if %anine%==3 echo "Mouth" is wrong.
if %anine%==3 echo Correct answer is 2, "Hands"
if %anine%==4 echo "All of the above" is wrong.
if %anine%==4 echo Correct answer is 2, "Hands"
pause
goto RESULTTEN
:RESULTTEN
echo Question ten of ten
echo Of the following only one action is acceptable. Select it.
if %aten%==1 echo "Using files without handles" is wrong.
if %aten%==1 echo Correct answer is 3, "Using clamps that are really big"
if %aten%==2 echo "Prying with a chisel" is wrong.
if %aten%==2 echo Correct answer is 3, "Using clamps that are really big"
if %aten%==3 echo "Using clamps that are really big" is correct.
if %aten%==4 echo "Hammering with a wrench" is wrong.
if %aten%==4 echo Correct answer is 3, "Using clamps that are really big""
pause
goto MAINMENU
:MARK
set mark= 0
if %aone%==2 set/a mark="%mark%+1"
if %atwo%==1 set/a mark="%mark%+1"
if %athree%==1 set/a mark="%mark%+1"
if %afour%==3 set/a mark="%mark%+1"
if %afive%==1 set/a mark="%mark%+1"
if %asix%==2 set/a mark="%mark%+1"
if %aseven%==3 set/a mark="%mark%+1"
if %aeight%==3 set/a mark="%mark%+1"
if %anine%==2 set/a mark="%mark%+1"
if %aten%==3 set/a mark="%mark%+1"
echo %mark%"/10" questions correct.
echo.
echo To see your answers, type 1
echo To go to the main menu, type 2
echo To exit the quiz, type 3
set/p markselection= Make your selection:
if %markselection%==1 goto RESULTONE
if %markselection%==2 goto MAINMENU
if %markselection%==3 goto ENDPROGRAM
:ACCREDITATION
cls
title Accreditation
echo -Information taken from Grade 9 shop question booklet
echo -Software used: Zed (available on chrome web store),
echo Notepad++ (available by google search),
echo Google drive and related services (available online)
echo -Creator: Exalor Stepaniuk (shop class grade censored, 2016/17)
echo.
pause
goto MAINMENU
:ENDPROGRAM
exit
Again, sorry if I did something wrong by dumping the entire script here. I just don't really know what i'm doing.
The root cause of your bug is this line in QUESTIONTEN:
set/p athree=
This looks like a typo in that you meant to set aten instead of athree.
More specifically, since aten was empty, within MARK, the comparison ends up being interpreted like this:
if ==3 set/a mark="[mark value]+1"
Notice that the left operand is empty. The line is being interpreted wrong, and that's why you're getting the error. Changing athree to aten will fix this, but there is a trick to fixing comparisons so that you don't break your script when one of your operands is null. Just put something on both sides. For example, surround your comparators by quotes.
if "%leftoperand%"=="%rightoperand%" ...
Then, even if one or both be empty, it won't terminate your script. It will just look like if ""=="".
Also, a general trick to debugging batch files is to narrow down where errors occur (and why) by putting echo statements, even simple ones, like echo 1 at strategic spots. Then, when you see a 1 in the output, you know that line was executed, and your error is after that line. Once you find the bad line that your script is terminating on, you can echo a copy of it to see what the script is interpreting it as, which will help you figure out the problem.
Like this:
echo if %aten%==3 set/a mark="%mark%+1"
if %aten%==3 set/a mark="%mark%+1"
I hope that helps.
Related
i am trying to make a text adventure, but i'm kind of clueless how to get an if/else statement to work with a variable. probably a few mistakes in my code:
# echo off
color 0a
echo This is a text adventure! to play, read through the story and at certain points you get to make decisions.
echo Remember, selecting an invalid option will automatically be counted as option 2!
echo have fun
pause
cls
echo You wake up in a dimly lit room. You can't seem to remember anything. Anything about you or how you got here, that is.
echo You walk towards the door. It is locked.
echo 1)Force the door open.
echo 2) look around for another means of escape.
set /p escape=
if %escape% = 1
cls
echo you get the door open, but an orc comes in and smashes your face.
echo get rekt buddy, game over.
pause
exit
else
goto dungeon
:dungeon
cls
echo well done.
pause
exit
If your if statement has has an accompanying else statement, you need to use parentheses. The else must also be in the format ) else (, like this:
# echo off
color 0a
echo This is a text adventure! to play, read through the story and at certain points you get to make decisions.
echo Remember, selecting an invalid option will automatically be counted as option 2!
echo have fun
pause
cls
echo You wake up in a dimly lit room. You can't seem to remember anything. Anything about you or how you got here, that is.
echo You walk towards the door. It is locked.
echo 1)Force the door open.
echo 2) look around for another means of escape.
set /p escape=
if "%escape%"=="1" (
cls
echo you get the door open, but an orc comes in and smashes your face.
echo get rekt buddy, game over.
pause
exit
) else (
goto dungeon
)
exit /b
:dungeon
cls
echo well done.
pause
exit
I've removed the blanks lines for aesthetic purposes; you can put them back in if you really want them. I also added a exit /b because having a goto followed by the label you're going to is bad form. The quotes in the if statement are there to prevent the script from breaking if the user enters nothing.
#echo off
set SCENARIO21=20
set WEAPON1=gun
set DOG1=buddy
set SCENARIO11=broken laptop
set ALIVE1=yes
:day51
cls
echo.
echo Player 1 %SCENARIO21% %WEAPON1% %SCENARIO11%
echo %DOG1%
echo.
echo.
echo Day 5
echo.
echo That was a close one, im glad i got that jacket off when i did...that could've ended really badly...
pause
cls
echo Dang this road seems to go on forever...
pause
cls
echo Woah...
pause
cls
echo That house looks...normal...
pause
cls
echo Is somebody in there?
pause
cls
echo Come on who would live in that house though...
pause
cls
echo Its old, worn down, the roof is bowed, the paint is peeling...
pause
cls
echo And ew...that furniture looks like something from the 2000s
pause
cls
echo Whoever lived there last must've been an old couple...really old...
pause
cls
echo Maybe there is someone in there
pause
cls
echo The windows look like they're sparkling...
pause
cls
echo Wow. Is that a...?
pause
cls
echo A um...what are those called...Oh yeah...
pause
cls
echo A plant?
pause
cls
echo No...it couldn't be
pause
cls
echo The world's last farmer died about 70 years ago...
pause
cls
echo The 2100s...
pause
cls
echo No one knows how to plant anything, let alone GROW anything anymore...
pause
cls
echo Atleast thats what i thought...
pause
cls
echo I wonder if i should go in...
pause
if %ALIVE1%==yes (
cls
echo Player 1
pause
cls
echo Player 1
echo This house gives me a strange feeling...i can't tell if it's good or bad...
echo -Yes (go in, check the house, maybe it has a planting guide...or maybe theres someone in there...and hey if there is someone, why wouldn't they help you)
echo -No (screw that, its not worth it, if you go in your gonna die, duh...anyways what could be of use in a house as old as the 2000s)
set /p SCENARIO51=Should you go in the house?
if %SCENARIO51%==yes (
cls
echo You walk into the home...
pause
cls
echo Hello?
pause
cls
echo *distant voice* Hello...why are you in my home?
pause
cls
echo Sorry sir...ma'm...um i wasn't trying to bother you...
pause
cls
echo *distant voice* You didn't answer my question...and it's sir, thank you...
pause
cls
echo Oh...i came in because i saw the plants outside...
pause
cls
echo *distant voice* And? Is that your only reason...
pause
cls
echo Well i haven't seen plants until now...i was wondering how?
pause
cls
echo *distant voice* YOU'VE NEVER SEEN PLANTS? THIS IS WHY I GO AGAINST THE SYSTEM...
pause
cls
echo What system sir?
pause
cls
echo *distant voice* If we're going to have a conversation come sit with me...walk to the end of the hall and take a left into my room...
pause
cls
echo You walked into the room of the strange voice and found an old man sitting in a chair that looked like a bubble of water being squished...
pause
cls
echo *Old Man* Im Alexander...im 170 years old...
pause
cls
echo H-h-how?
pause
cls
echo *Alexander* Okay i don't have all day i must attend to other things...I'll tell you what
echo I'll answer 1 question...any question...
pause
cls
if %SCENARIO51%==yes
echo This is your chance...
echo -1 (How did this all start?)
echo -2 (How do i get to the city of Lillian?)
echo -3 (How do i live forever just like you?)
set /p SCENARIOP51=What would you like to ask?
if %SCENARIOP51%==1 (
cls
echo *Alexander* Wow...good question...
echo It started in 2100...
pause
cls
echo When the last farmer died?
pause
cls
echo *Alexander* No, when the last farmer turned immortal...me
pause
cls
echo No i saw it on the news drone...he's dead...
pause
cls
set CODE=LSON5676
echo *Alexander* AGAIN...Sorry, that was the system's news drone...they tend to "confuse" everyone's story to make themselfs look better...
echo Anyways...in 2100 two groups of hacking experts went to war...
pause
cls
echo It ended when one of the groups found a way to literally melt the other groups computers into green radioactive goop...
echo No one really knows for sure how the war was started but most say it was because one group had a hostage...
pause
cls
echo The hostage was said to be the head hacker for the opposing group that was finding some cure...his name was Larson...
echo But for some reason when asking for Larson back the opposing group requested they send %CODE% back...
pause
cls
echo That sounds like a code...
echo better write it down...
echo %CODE%
pause
cls
echo *Alexander* It was all for some stupid reason in my opionion anyways...
echo But back to what happened...
echo After they figured out how to turn the computer into this green goop..they did it to all their computers...
echo Little did they know the goop became radioactive Artificial Intelligence...it could think on its own...
echo And it spread like wild fire...any technology it touched became more green goop...
echo Something else they didn't realize is the goop could sink into your skin with no problem at all...
echo It goes into your veins and overclocks your heart...
echo It was a nano-technology weapon...atomic level capabilities...
echo It was a devastation...
echo And thats all i know...
pause
cls
echo Thank you Alexander...this information won't go to waste...
pause
set ALIVE1=yes
)
if %SCENARIOP51%==2 (
cls
set CODE=5676
echo *Alexander* HA! thats simple...
echo you're not that far either...
echo Go down the road and take the 3rd right
echo You'll be right in front of it...
pause
cls
echo You followed his advice and fell into a trap
pause
cls
type "the end.txt"
pause
cls
set ALIVE1=no
)
if %SCENARIOP51%==3 (
cls
echo *Alexander* Come with me ill show you...
echo This guy seems kinda fishy...
echo Go (go with Alexander to find out what makes him live forever)
echo Leave (Don't follow Alexander, say you have a group waiting outside and you need to get back to them...)
)
if %SCENARIOP51%==3 (
set /p SCENARIOPP51=Do you want to follow Alexander?
)
if %SCENARIOP51%==3 (
if %SCENARIOPP51%==go (
cls
set CODE=LSON5676
echo *Alexander* you aren't smartest are you?
pause
cls
echo You turn around and...
pause
cls
echo *BANG*
pause
cls
echo You died...
pause
cls
type "the end.txt"
pause
set ALIVE1=no
)
if %SCENARIOPP51%==leave (
cls
set CODE=LSON5676
echo *Alexander* I know you're not with anyone but that dog of yours %DOG1%...
pause
cls
echo How do you know his name?
pause
cls
echo *Alexander* you called him to come as you walked down the street cause he was sniffing something...i over heard...
echo I respect your efforts to not fall into traps though...
echo Take this...
pause
cls
echo Alexander handed you a small square of yellow paper with the writing %CODE% on it...
pause
cls
echo *Alexander* take the sticky note and get out...
pause
cls
echo You take the sticky note and leave the house...
pause
cls
echo Whats a sticky note?
pause
)
)
if %SCENARIO51%==no (
cls
echo That thing gives me the creeps...
echo Bye bye house of horror...
set SCENARIO51=none
pause
set ALIVE1=yes
)
)
)
set END=0
if %ALIVE1%==no (
set /a END=%END%+1
)
if %END%==1 (
exit
)
goto day61
:day61
echo yay!
pause
exit
I've tried everything, im very new to coding hence the simple codes but im so confused on what's wrong. I've been coding this 4 player game for about 4 days and i've been stuck trying to fix this specific code. Whenever i load up the game I can get here and get through each scenario but then for instance if i chose to ask the first question I could get through all the dialogue BUT the %CODE% doesn't show up because #echo is off. Also, after completing the 1st question it will still ask me this part:
if %SCENARIOP51%==3 (
cls
echo *Alexander* Come with me ill show you...
echo This guy seems kinda fishy...
echo Go (go with Alexander to find out what makes him live forever)
echo Leave (Don't follow Alexander, say you have a group waiting outside and you need to get back to them...)
)
if %SCENARIOP51%==3 (
set /p SCENARIOPP51=Do you want to follow Alexander?
)
Even though %SCENARIOP51%==1 it still has me set /p SCENARIOPP51 even though %SCENARIOP51% doesn't equal 3. Please Help It Would Be Veryyyyyy Appreciated. Thanks! :)
if %ALIVE1%==yes (
cls
echo Player 1
pause
cls
echo Player 1
echo This house gives me a strange feeling...i can't tell if it's good or bad...
echo -Yes (go in, check the house, maybe it has a planting guide...or maybe theres someone in there...and hey if there is someone, why wouldn't they help you)
Note that this fortuitous? ) ends the if. If you want to actually show the ) here then you need to escape the ) by coding ^). The drawback though is that your if is then not closed for a large number of lines (I'm not going to look through all that code) - and your if %SCENARIO51% opens (another) nested code-block.
Within a code-block (a parenthesised sequence of lines) any %var% is replaced by the value of that variable when the instruction controlling the block (if, for) is encountered. Hence, your set/p which varies SCENARIO51 will appear to use the previous value of SCENARIO51 for %SCENARIO51% within the block.
You need to look at delayedexpansion - hundreds of SO articles about that.
And also be warned : replying Enter alone to a set/p will leave the variable unchanged.
Since you are using set/p you should also use the format
if "%varname%"=="targetstring" ...
in order to have some immunity to empty/separator-containing strings.
Further, the /i switch applied to if will make the comparison case-insensitive.
And it may benefit you to learn batch subroutines. See call /? from the prompt for documentation.
So i was writing a Batch file, and i made a file that you can choose an answer by a question, and its saves it automaticly to a file. But i want to make something before it saves it to a file, to let people confirm their choices. Simplified, i have it like this:
Rem Question 1 appearance
:q1
cls
Echo.
Echo Please select your age:
Echo ==================
Echo A) younger than 18
Echo B) 18-30
Echo C) 30-45
Echo D) older than 45
Echo.
Echo.
Rem Question 1 in- and output settings
:q1.2
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose an age of less than 18. & pause & goto q2
if "%INPUT%"=="B" Echo You chose an age of 18-30. & pause & goto q2
if "%INPUT%"=="C" Echo You chose an age of 30-45. & pause & goto q2
if "%INPUT%"=="D" Echo You chose an age of older than 45. & pause & goto q2
Echo Please enter a valid answer!
goto q1.2
Rem question 2 appearance
:q2
Echo Answer: %INPUT% >>Question1answers.txt
cls
Echo.
Echo Please select your favourite colour:
Echo ==========================
Echo A) Blue
Echo B) Red
Echo C) Green
Echo D) Yellow
Echo E) Other
Echo.
Echo.
Rem Question 2 in- and output settings
:q2.1
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose blue.&pause&goto end
if "%INPUT%"=="B" Echo You chose red.&pause&goto end
if "%INPUT%"=="C" Echo You chose green.&pause&goto end
if "%INPUT%"=="D" Echo You chose yellow.&pause&goto end
if "%INPUT%"=="E" Echo You chose something else.&pause&goto end
Echo Please enter a valid answer!
goto q2.1
So i ask you to not reply with the full code, maybe a little piece so i can learn from it and put it in myself, you know? Thanks!
Edit:
So now i added this part:
:confirmation
cls
Echo Please make sure this is your data:
if "%INPUTT%"=="A" Echo You chose an age of less than 18.
if "%INPUTT%"=="B" Echo You chose an age of 18-30.
if "%INPUTT%"=="C" Echo You chose an age of 30-45.
if "%INPUTT%"=="D" Echo You chose an age of older than 45.
echo.
if "%INPUT%"=="A" Echo You chose blue as your favourite colour.
if "%INPUT%"=="B" Echo You chose red as your favourite colour.
if "%INPUT%"=="C" Echo You chose green as your favourite colour.
if "%INPUT%"=="D" Echo You chose yellow as your favourite colour.
if "%INPUT%"=="E" Echo You chose something else as your favourite colour.
choice /m "Is this your data?" /d Y
if %errorlevel%==1 goto q1
Echo Answer: %INPUTT% >>Question1answers.txt
Echo Answer: %INPUT% >>Question2answers.txt
So i started debugging and when i came to the part it was wrong, it let me through and still saved my input. it kind of ignores the part of
if %errorlevel%==1 goto q1
so what do i do now?
since you ask for a short snippet, this should do what you want:
set /p "age=Enter your age: "
choice /M "Your age is %age%, correct?"
if %errorlevel%==1 goto :correct
echo false
goto :eof
:correct
echo true
I made this code for something to remind me about certain things I need to do, but for some reason the code isn't working.
#echo off
cls
echo Welcome to ChoreHub
echo -------------------------------------------
echo Today's List:
echo * Do School
echo * Practice Piano
echo * Check to Make Sure House is Clean
echo * Check to Make Sure Room is Clean
echo -------------------------------------------
echo What chore have you finished? (1, 2, 3, 4)
set /P chore=
if %chore%=="1" goto :1
if %chore%=="2" goto :2
if %chore%=="3" goto :3
if %chore%=="4" goto :4
goto bro
When I put in a right answer, it skips over the if statements and goes straight to the bottom.
I'm not sure why, I am a little rusty on batch files though. If anyone could help me that would be great, thanks!
you haven't set anything? where is 1,2,3 and bro? where is it supposed to go??
you need to add this
:1
echo 1 is selected
goto :end
2:
echo 2 is selected
goto :end
:3
echo 3 is selected
goto :end
:end
check this fully working batch example
Hard to tell without seeing all your code, but I think, your problem is here:
if %chore%=="1" goto :1
You are comparing your variable with "1" (not just 1 what you seem to think)
You need to enter "1" ( Quote 1 Quote ) to match this.
Better code:
if "%chore%"=="1" goto :1
(Note: if %chore%==1 seems to be correct too, but will give a syntax error, if %chore% is empty)
My idea was to have it start when the computer boots and then ask me what game do I want to play. That's simple but I want to be able to answer different answers like: Is the input like CS:GO,cs,csgo,counter strike, and so forth and, here's how I tried to do it=
if %game%==1,CS:GO,cs:go,csgo,"Counter Strike","counter strike" goto cs
But as you probably know, it did not work. so the question is how to make it so that "%game%" can be a lot of different things and still goes to the same thing without having to do multiply if %GAME%==...?
and here's the whole code if you want to see it=
#echo off
color a
cls
:start
echo what game do you want to play?
echo 1/"CS:GO"? -"Counter Strike: Global Ofensive"
echo 2/"H&G"? -"Heros & Generals"
echo 3/"P2"? -"Portal 2"
echo 4/"UT"? -"Unturned"
echo 5/"LO"? -"Loadout"
echo 6/"DAB"? -"Double Action Boogaloo"
set /p game=vwhat game?:
if %game%==1,CS:GO,cs:go,csgo,"Counter Strike","counter strike" goto cs
pause
goto start
:start
echo what game do you want to play?
echo 1/"CS:GO"? -"Counter Strike: Global Ofensive"
echo 2/"H&G"? -"Heros & Generals"
echo 3/"P2"? -"Portal 2"
echo 4/"UT"? -"Unturned"
echo 5/"LO"? -"Loadout"
echo 6/"DAB"? -"Double Action Boogaloo"
set /p game=what game?:
echo /1/CS:GO/csgo/Counter Strike/ |find /i "/%game%/">nul && goto cs
rem other games here...
pause
goto start
/i makes the findcase insensitive, so it will find CSGO, CsGo, cSgO,...
&& works as "if previous command (find) was successful, then..."