In this qustion, Save and Load .bat game I used Mat\'s answer.
But now I have a problem with \"saving\" numbers using said answer.
If the variable is not double
The problem is Mat's solution! For better understanding I repeat his solution
@echo @ECHO OFF > savegame.cmd
@echo SET ITEMS=%ITEMS% >> savegame.cmd
@echo SET HEALTH=%HEALTH% >> savegame.cmd
@echo SET MONEY=%MONEY% >> savegame.cmd
In my opinion, it has multiple disadvantages.
The @
prefix isn't necessaray.
The redirection is repeated for each line (I don't like redundancy).
It needs the spaces, as without spaces you got problems with numbers.
Sample with items=1
@echo set ITEMS=1>>savegame.cmd
This results not in writeing set items=1
it writes set items=
to 1>>savegame.cmd
1>> is the standard stream.
You can solve all problems with
(
echo @ECHO OFF
echo SET "ITEMS=%ITEMS%"
echo SET "HEALTH=%HEALTH%"
echo SET "MONEY=%MONEY%"
) > savegame.cmd
The quotes are used to ensure that "hidden" spaces after the set are ignored.
Btw. It's a bad idea to use a construct like if %raghave% = 00
, (you need two equal signs), as 00
isn't a normal number you can't count or calculate with it, it's better to use 0
instead.
Then also this should work
set /a items=0
set /a items=items+1
set /a items=items-1
if %items%==0 echo There are no items