在 IF 批处理程序中创建变量时,变量不起作用

在 IF 批处理程序中创建变量时,变量不起作用

我正在尝试制作一款游戏,每当我尝试时,它都会说语法错误,但实际上它是正确的

:Q3

echo ====================================
echo Do you want to be skilled in:
echo.
echo Speed (1)
echo Enchanting (2)
echo Pickpocket (3)
echo Attack (4)
echo Magic (5)
echo.
echo Say the Number it's labeled as. (1-5)
echo.
echo =====================================

set /p QU3= %NAME%\

if %QU3%== 1 SET SPEE= 1
if %QU3%== 2 set ECH= 1
if %QU3%== 3 set PIC= 1
if %QU3%== 4 set 
if %QU3%== 5 

pause
goto Q4

请尽快帮助我!

答案1

我不确定你想做什么,但是试试这个:

@echo off
:Q3

echo ====================================
echo Do you want to be skilled in:
echo.
echo Speed (1)
echo Enchanting (2)
echo Pickpocket (3)
echo Attack (4)
echo Magic (5)
echo.
echo Say the Number it's labeled as. (1-5)
echo.
echo =====================================

SET /P QU3="INPUT:"

if "%QU3%"==1 (SET SPEE=1)
if "%QU3%"==2 (SET ECH=1)
if "%QU3%"==3 (SET PIC=1)
REM if "%QU3%"== 4 set 
REM if "%QU3%"== 5 

echo %QU3% was selected
pause

我建议您阅读本教程以了解有关批处理文件语法的更多信息:http://steve-jansen.github.io/guides/windows-batch-scripting/index.html

答案2

在网站上看了一会儿后,我明白了。这是我得到的::Q3

echo ====================================
echo Do you want to be skilled in:
echo.
echo Speed (1)
echo Enchanting (2)
echo Attack (3)
echo Magic (4)
echo.
echo Say the Number it's labeled as. (1-5)
echo.
echo =====================================

set SPEE=0
set ENCH=0
set ATTA=0
set MAGI=0

set /p QU3= %NAME%\

if %QU3%== 1 set /a SPEE+=1
if %QU3%== 2 set /a ENCH+=1
if %QU3%== 3 set /a ATTA+=1
if %QU3%== 4 set /a MAGI+=1

pause

相关内容