Reputation: 75
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
Upvotes: 5
Views: 103
Reputation: 37589
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!
Upvotes: 3
Reputation: 42494
You have to enable delayed expansion
SETLOCAL ENABLEDELAYEDEXPANSION
set VAR=before
set VAR=after & echo immediate:%VAR%, delayed:!VAR!
ENDLOCAL
As explained by Raymond Chen
Upvotes: 0