Link to home
Start Free TrialLog in
Avatar of Henry Kertauferpaufer
Henry Kertauferpaufer

asked on

How do you subtract a number from a variable in a batch file?

I can't figure out how to make a lives system for my game and I need to know how.

Here is my code for the lives;

SET lives=5

:Scene1
CLS
ECHO  o       Woof!
ECHO /0\   ,###@'
ECHO / \     /   \
ECHO #########################################
ECHO.
ECHO You are walking along the dirt
ECHO road with your backpack and trusty dog Steve.
ECHO You have !lives! lives.
PAUSE
CLS

. . .

:WinFight1

SET /a lives-=1
CLS

ECHO  o
ECHO /0\    ,###@                      w   \__,.  \__,.
ECHO / \      /   \                        3--`~  /--,^  /--,^
ECHO #########################################
ECHO.
ECHO You won the fight!
ECHO You now have !lives! lives.
PAUSE
GOTO Scene2

Open in new window



I expected it to output 'You have 5 lives.' in the first section, and 'You now have 4 lives.' in the second part, but instead, I got 'You have !lives! lives and 'You now have !live! lives.'
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

SET lives=5

:Scene1
CLS
ECHO  o       Woof!
ECHO /0\   ,###@'
ECHO / \     /   \
ECHO #########################################
ECHO.
ECHO You are walking along the dirt
ECHO road with your backpack and trusty dog Steve.
ECHO You have %lives% lives.
PAUSE
CLS

. . .

:WinFight1

SET /a lives-=1
CLS

ECHO  o
ECHO /0\    ,###@                      w   \__,.  \__,.
ECHO / \      /   \                        3--`~  /--,^  /--,^
ECHO #########################################
ECHO.
ECHO You won the fight!
ECHO You now have %lives% lives.
PAUSE
GOTO Scene2

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What a shame the OP has not responded, I really got carried away getting into how he could enhance this a lot further