I made a game menu and the "2" works gret but when i click "5" it adds +1 to "menumark" BTW I have Windows 7. Some more questions: 1) Can you put a color to a specific letter? 2) Why doesnt: if errorlevel 3 set /a menumark=%menumark%-1 work? Code:
我做了一个游戏菜单,“2”工作得很好,但当我点击“5”时,它为“menumark”增加了+1 BTW我有Windows 7.还有一些问题:1)你能把颜色添加到特定字母吗? 2)为什么不:如果errorlevel 3设置/ menumark =%menumark%-1工作?码:
...
...
...
set menumark=1
set checkmark=1
set mark1=/
set mark2=.
set mark3=.
...
...
...
:MENU
cls
echo ----------
echo %mark1% (1) Play.
echo %mark2% (2) Settings.
echo %mark3% (3) Scores.
echo ----------
choice /c 25 /n
if errorlevel 1 set /a menumark=%menumark%+1
if errorlevel 2 set checkmark=2
if %menumark%==4 set menumark=1
if %menumark%==0 set menumark=1
if %menumark%==1 set mark1=/&set mark2=.&set mark3=.
if %menumark%==2 set mark2=/&set mark1=.&set mark3=.
if %menumark%==3 set mark3=/&set mark2=.&set mark1=.
if %checkmark%==2 if %menumark%==1 goto TOP
if %checkmark%==2 if %menumark%==2 goto SETTINGS
if %checkmark%==2 if %menumark%==3 goto HIGHSCORE
goto MENU
...
...
...
1 个解决方案
#1
2
Your problem is the control of errorlevel
. The code if errorlevel n command
will execute the indicated command for any errorlevel
value greater or equal to n
. For this reason, to use this kind of testing it is necessary to test from greater to lower values of errorlevel
and properly code to avoid problems
你的问题是对errorlevel的控制。如果errorlevel n命令的代码将对任何大于或等于n的errorlevel值执行指示的命令。出于这个原因,要使用这种测试,有必要从更高到更低的errorlevel值进行测试并正确编码以避免出现问题
if errorlevel 3 echo 3
if errorlevel 2 echo 2
if errorlevel 1 echo 1
if your errorlevel is 3, the previous code will echo the three values, as all the conditions are evaluated to true.
如果您的errorlevel为3,则前面的代码将回显这三个值,因为所有条件都被计算为true。
if errorlevel 3 (
echo 3
) else if errorlevel 2 (
echo 2
) else if errorlevel 1 (
echo 1
) else echo no error level
if %errorlevel%==3 echo 3
if %errorlevel%==2 echo 2
if %errorlevel%==1 echo 1
Both versions will avoid the "problem" (or you can use goto
s to avoid falling through the options)
两个版本都将避免“问题”(或者您可以使用gotos来避免掉落选项)
For the color management, here you can find all the required information.
对于颜色管理,您可以在此处找到所有必需的信息。
#1
2
Your problem is the control of errorlevel
. The code if errorlevel n command
will execute the indicated command for any errorlevel
value greater or equal to n
. For this reason, to use this kind of testing it is necessary to test from greater to lower values of errorlevel
and properly code to avoid problems
你的问题是对errorlevel的控制。如果errorlevel n命令的代码将对任何大于或等于n的errorlevel值执行指示的命令。出于这个原因,要使用这种测试,有必要从更高到更低的errorlevel值进行测试并正确编码以避免出现问题
if errorlevel 3 echo 3
if errorlevel 2 echo 2
if errorlevel 1 echo 1
if your errorlevel is 3, the previous code will echo the three values, as all the conditions are evaluated to true.
如果您的errorlevel为3,则前面的代码将回显这三个值,因为所有条件都被计算为true。
if errorlevel 3 (
echo 3
) else if errorlevel 2 (
echo 2
) else if errorlevel 1 (
echo 1
) else echo no error level
if %errorlevel%==3 echo 3
if %errorlevel%==2 echo 2
if %errorlevel%==1 echo 1
Both versions will avoid the "problem" (or you can use goto
s to avoid falling through the options)
两个版本都将避免“问题”(或者您可以使用gotos来避免掉落选项)
For the color management, here you can find all the required information.
对于颜色管理,您可以在此处找到所有必需的信息。