SukkaBileet
SukkaBileet

Reputation: 13

I was unexpected at this time

I am making card game with batch-file but I get I was unexpected at this time so what i can do without changing variables.

set n1=IJ I
set m1=I HI
set n2=IJ I
set m2=I DI
if %n1%==%n2% (
    if %n1%==IJ I set WL=win
)else (
set WL=lose
)
echo +--+ +--+
echo %n1% %n2%
echo %m1% %m2%
echo +--+ +--+
echo   %WL%

so do I need to change the shape of card or what?

Upvotes: 1

Views: 331

Answers (2)

aphoria
aphoria

Reputation: 20209

You need to use quotes around the variables and values in the IF statements.

Like this:

set n1=IJ I
set m1=I HI
set n2=IJ I
set m2=I DI
if "%n1%"=="%n2%" (
    if "%n1%"=="IJ I" set WL=win
) else (
set WL=lose
)
echo +--+ +--+
echo %n1% %n2%
echo %m1% %m2%
echo +--+ +--+
echo   %WL%

Upvotes: 1

Billy Ferguson
Billy Ferguson

Reputation: 1439

The expression doesn't evaluate to anything, that's why it is saying I is not expected. I think those are supposed to be strings? What you currently have is two symbols IJ and I with no operator which just doesn't work. Those 4 sets at the top should possibly be wrapped in quotes, but I'm purely guessing, like the following:

set n1="IJ I"
set m1="I HI"
set n2="IJ I"
set m2="I DI"
if %n1%==%n2% (
    if %n1%==IJ I set WL=win
) else (
set WL=lose
)
echo +--+ +--+
echo %n1% %n2%
echo %m1% %m2%
echo +--+ +--+
echo   %WL%

Upvotes: 0

Related Questions