Bat*_*Man 5 if-statement batch-file set
试图制作一个测验show.bat文件并在If-Set编码时遇到问题:
: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
Run Code Online (Sandbox Code Playgroud)
这是我遇到问题的地方:
if "%Bonus1Tries%"=="3" set Bonus1Tries=2 &echo you only have %Bonus1Tries% left!
Run Code Online (Sandbox Code Playgroud)
该编码中唯一不起作用的部分是:
you only have 3 tries left!
Run Code Online (Sandbox Code Playgroud)
代替
you only have 2 tries left!
Run Code Online (Sandbox Code Playgroud)
意思就是
设置Bonus1Tries = 2
不工作.你能帮忙吗,并提前感谢你!-Batch Man
在您需要的代码块内delayed expansion,或者拆分命令(如果可能):
if "%Bonus1Tries%"=="3" set "Bonus1Tries=2"
if "%Bonus1Tries%"=="2" echo you only have %Bonus1Tries% left!
Run Code Online (Sandbox Code Playgroud)