-1

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:

...
...
...
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
...
...
...
TamirGali
  • 1
  • 1

1 Answers1

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

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.

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 gotos to avoid falling through the options)

For the color management, here you can find all the required information.

Community
  • 1
  • 1
MC ND
  • 65,671
  • 6
  • 67
  • 106