简体   繁体   中英

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?

Also worth it to add a IF EXIST savegame.cmd ECHO "Do you want to overwrite a previous save?" ELSE @echo SET ITEMS=%ITEMS% > savegame.cmd

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

I'm no expert, but i think this might help.

if savegame.cmd EQU true goto yes NEQ true goto no

:yes
echo Override Current Save?
<SAVE METHOD HERE>

:no
<SAVE METHOD HERE>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM