字符串检查错误地返回true

时间:2015-06-15 13:07:33

标签: batch-file

所以我一直在玩,试图制作一个简单的批量游戏。

那么我现在做错了什么?

以下是代码:

:promotions_sucessful
cls
if %division%==Bronze V (
set league=Bronze IV
set lp=0
echo You have been promoted!
del promotion.txt
pause>nul
goto menu
)
if %division%==Bronze IV (
set league=Bronze III
set lp=0
echo You have been promoted!
del promotion.txt
pause>nul
goto menu
)

所以现在即使将该部门设置为青铜IV,它也会转到青铜V为什么? 有人可以解释我做错了什么以及我应该改变什么。

如果需要,我可以提供更多信息。

1 个答案:

答案 0 :(得分:1)

您需要在if-statements中使用引号:

:promotions_sucessful
cls
if "%division%"=="Bronze V" (
set league=Bronze IV
set lp=0
echo You have been promoted!
del promotion.txt
pause>nul
goto menu
)
if "%division%"=="Bronze IV" (
set league=Bronze III
set lp=0
echo You have been promoted!
del promotion.txt
pause>nul
goto menu
)