Search code examples
batch-fileloadsavechanges

How to load in a batch file?


I'm trying to make a .bat game and have most of the codeing already done. I looked up how to have the player save and load and it told me to save with this

@echo SET ITEMS=%ITEMS%   >> savegame.cmd

So it would save on savegame.cmd but how do i Load that information from savegame.cmd back to my .bat file?


Solution

  • The command you're using to save creates a .cmd file with the contents SET ITEMS=<items> where <items> is the current value of the ITEMS variable. To load this variable again, simply

    call savegame.cmd

    and the ITEMS variable will be set to the value stored in the samegame.cmd file.

    Also, it's worth nothing that >> adds text to the end of the file while > writes a new file every time. If you think you're going to be saving a lot, it may be worth considering making the save command @echo SET ITEMS=%ITEMS% > savegame.cmd