Im coding a .bat game and I need a way to increase/decrease health and money. I just want a smallish command instead of:
if %money%=05 set %money% 00
if %money%=10 set %money% 05
if %money%=15 set %money% 10
if %money%=20 set %money% 15
if %money%=25 set %money% 20
if %money%=30 set %money% 25
and etc. Is there just a command that subtracts or adds a specific number to a variable?
http://www.dostips.com/DtTipsArithmetic.php
How to do math in batch?
Moderator: DosItHelp
-
- Posts: 1
- Joined: 24 Sep 2017 03:36
How to do math in batch?
Last edited by aGerman on 24 Sep 2017 04:42, edited 1 time in total.
Reason: changed the meaningless topic name
Reason: changed the meaningless topic name
Re: How to do math in batch?
The command you're looking for is SET /A.
... subtracts 5 from the former value of %money%. Note that 05 is an octal number. For the beginning you should rather avoid leading zeros.
Also:
Steffen
Code: Select all
set /a "money-=5"
Also:
The = is the assignment operator. The equality comparison operator would have been the ==.if %money%=05
Double false. 1) the assignment operator is missing. 2) You have to assign to the variable name (without percent signs).set %money% 00
Steffen