Kaisha Mina
Kaisha Mina

Reputation: 3

BATCH Unable to join variables

I don't know what I got wrong here. Please help!

if "House%Player1Block%==1" goto HouseEventP11
if "House%Player1Block%==2" goto HouseEventP12
echo.You landed on empty block. Claiming house.
echo.You now own block %Player1Block%.
set "House%Player1Block%=1"

Error was Goto was unexpected at this time.

Upvotes: 0

Views: 42

Answers (1)

Stephan
Stephan

Reputation: 56208

if "House%Player1Block%==1" goto HouseEventP11

if syntax is: if <value1> <comparator> <value2> command
So "House%Player1Block%==1" is value1, goto is the comparator - wait - what? goto isn't a comparator - goto was unexpected at this time.

Correct syntax:

if "House%Player1Block%" == "1" goto :HouseEventP11

(Note: the colon with goto :label is optional, but I like to have it to be consistent with the call command, where the colon is mandatory to call a label (without the colon, call would try to find another batchfile instead of a label))

Upvotes: 2

Related Questions