Darth Tater
Darth Tater

Reputation: 477

Errors from If statements?

I have a 456 line batch file, and close to the end it is stuffing up on if statements comparing variables on all of the following

if "%user%" EQU "%temp%"
if %user% EQU %temp%
if %user% == %temp%
if "%user%" == "%temp%"
if %user% == 0
if "%user%" == "0"
if %user% EQU 0
if "%user%" EQU "0"

It comes up with an error saying

The syntax of the command is incorrect

(temp is always equal to 0, and user is equal to 2, 1, or 0)

The syntax error occurs if the first 2 lines don't have echo ... at the end of them

if "%enemy%" == "%temp%"( echo ...
  if NOT '%choice%'=='1'( echo ...
    if %enemyat% GTR %resistance% ( 
      set /a health-=1
      set /a resistance=16+8*%resistancelvl%
    ) else ( 
      set /a resistance-=%enemyat%
    )
  )
)

Upvotes: 0

Views: 124

Answers (2)

Adit
Adit

Reputation: 86

Try if %user%==0or if %user%==%temp%.

Notice the lack of spacing between the '==' and the variables.

Upvotes: 0

SomethingDark
SomethingDark

Reputation: 14325

You're missing a space before the ( on the first two lines.

if "%enemy%"=="%temp%" ( 
    if NOT '%choice%'=='1' ( 
        if %enemyat% GTR %resistance% ( 
            set /a health-=1
            set /a resistance=16+8*%resistancelvl%
        ) else ( 
            set /a resistance-=%enemyat%
        )
    )
)

Upvotes: 2

Related Questions