Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
790 views
in Technique[技术] by (71.8m points)

batch file - Save and Load .bat game

I'm making a text game written in bat, and the game has been done, (or more, a good part of it, such as the commands, and at the stage where you can play it); however, I want to add the power to save your game, and load it again.

I think one could do this by having the .bat file write the variables which need to be saved (such as the item variables); however, I don't know how to do this. Any help would be appreciated, thanks.

I should have said, I can make it load, by use of:

 for /f "delims=" %%x in (config.txt) do (set "%%x")

However, I don't know how to make the .bat write to the file and so "save".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could also save/load with only values, like

(
  echo %highscore%
  echo %playername%
  echo %points%
) > savegame.sav

and load them with

< savegame.sav (
  set /p highscore=
  set /p playername=
  set /p points=
)

The first part simply redirects the echo outputs to a file.
The loading part using also file redirection, but in this case as input source.
set /p commands in a block can read consecutively lines from the file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...