If statement 在If命令之后设置命令
正在尝试制作quicky show.bat文件,但在If Set编码方面遇到问题:If statement 在If命令之后设置命令,if-statement,batch-file,set,If Statement,Batch File,Set,正在尝试制作quicky 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
: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
这就是我的问题所在:
if "%Bonus1Tries%"=="3" set Bonus1Tries=2 &echo you only have %Bonus1Tries% left!
编码中唯一不起作用的部分是:
you only have 3 tries left!
而不是
you only have 2 tries left!
也就是说
设置Bonus1Tries=2
它不起作用了。
请你帮忙,提前谢谢你-批处理人员您必须启用延迟扩展
SETLOCAL ENABLEDELAYEDEXPANSION
set VAR=before
set VAR=after & echo immediate:%VAR%, delayed:!VAR!
ENDLOCAL
如所述,在代码块中,您需要延迟扩展,或者拆分命令(如果可能):
if "%Bonus1Tries%"=="3" set "Bonus1Tries=2"
if "%Bonus1Tries%"=="2" echo you only have %Bonus1Tries% left!