Open a command prompt window, run set /?
and read all help pages output into the console window.
The option /A
is for arithmetic expressions and should be never used to assign a string value to an environment variable. Environment variables are always of type string.
On the line
set /a partner=Ignite
the Windows command processor interprets Ignite
as name of an environment variable which string value converted to an integer value should be assigned to variable partner
converted back from integer to string. As there is most likely no variable Ignite
the value 0 is assigned to partner
as string.
On the line
set /a move3=Flame Spread
the Windows command processor interprets Flame
and Spread
as name of environment variables. But there is no operator between and therefore the arithmetic expression is invalid because of the missing operator.
The solution:
@echo off
setlocal EnableDelayedExpansion
set "confirm=n"
set /P "confirm=y/n : "
if /I "!confirm!" == "y" (
set "partner=Ignite"
set "monsterlevel=5"
set "reqexp=100"
set "currentexp=0"
set "element=Fire"
set "evolution=Igneous"
set "move1=Scratch"
set "move2=Burn"
set "move3=Flame Spread"
set "move4=Quick Slash"
set "hp=100"
goto mymonster
)
if /I "!confirm!" == "n" goto pick
rem The user has entered whether y/Y nor n/N. What to do now?
The environment variable confirm
is defined with a default value in case of batch user just hits RETURN or ENTER without entering anything at all. In this case the environment variable confirm
keeps its current value or is still undefined if not defined before.
The string comparison is done case-insensitive because of IF option /I
. Run in a command prompt window if /?
for help on this command .
And the string comparison is done with using delayed expansion. This is for security as the batch user could enter by mistake or intentionally for example "<
and making the string comparison now without using delayed expansion the batch processing would immediately exit on first IF condition line because of a syntax error.
Always use double quotes and not single quotes on comparing strings. Double quotes have a special meaning for Windows command processor on evaluating an IF condition, but single quotes don't. The character '
is interpreted on a string comparison with ==
like a letter or a digit, it has no special meaning. But please note that the Windows command processor compares the strings left and right of ==
with including the double quotes. So not the strings inside the double quotes are compared, but the strings with the double quotes which means if /I "!confirm!" == y
would be never true.
See also the answer on How to set environment variables with spaces?