Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set commands after an If command

Trying to make a quiz show.bat file and having trouble with the If-Set coding:

:10    
echo @: (Press any key to continue)
pause >nul
cls
echo Bonus Question 1:
echo Translate the letters in CAPS.
echo @: Copy the sentence and translate the words in CAPITALS.
echo Il nome di mia ZIA e Gabriella e il nome di mio ZIO e Nick.
echo @: Careful, you only get 3 goes!
echo @: now you try!
set /p BonusAnswer1=">"
set /p BonusAnswer1=">"
if "%BonusAnswer1%"=="Il nome di mia aunty Gabriella e il nome di mio uncle Nick. echo well done! &goto:11
if "%BonusAnswer1%"=="Hint" echo @: Copy the sentence and translate ZIA and ZIO. Only put a capital for Il, Gabriella and Nick. &goto:10

here is where I have the problem:

if "%Bonus1Tries%"=="3" set Bonus1Tries=2 &echo you only have %Bonus1Tries% left!

the only part of that coding that isn't working is it says:

you only have 3 tries left!

instead of

you only have 2 tries left!

which means that

set Bonus1Tries=2

isn't working. Can you help please and thank you in advance! -Batch Man

like image 528
Batch Man Avatar asked Oct 21 '22 04:10

Batch Man


1 Answers

inside a code block you need delayed expansion, or you split the command (if possible):

if "%Bonus1Tries%"=="3" set "Bonus1Tries=2"
if "%Bonus1Tries%"=="2" echo you only have %Bonus1Tries% left!
like image 151
Endoro Avatar answered Oct 27 '22 23:10

Endoro