Is there a way to make a checkpoint system in batch files? I'm teaching myself batch, and creating a text-based RPG type game, but if the program is closed, it starts back at the very beginning of the code, with no progress saved. I want to make a complex long term game, but I don't want to have to deal with a restart of the game every time. Is there a way to save progress so you can re-open the program and either restart OR resume where you left off, with all previous choices intact?
Asked
Active
Viewed 179 times
2 Answers
1
Possibly the easiest save/reload method is this:
Reserve a character (say, #
) to be used as the first character of all of the variables you want to record.
so...
set #points=35
set action=3
set #money=22
To save all of the #
variables, use
set #>filename
which would save #money
and #points
, but not action
To reload use
for /f "delims=" %%a in (filename) do set "%%a"
which will reload all of the variables saved in the file - which are, of course, only #variables.

Magoo
- 77,302
- 8
- 62
- 84
0
In addition to magoo's answer regarding a very efficient save / load method, (with a slight modification): scripting user profiles can be done like so:
@Echo off
rem /* predefine your key variables prior to this loop */
:name :# load point
Set /P "name=Enter your name: "
If Not "%name%" == "" (
rem /* If character exists; load */
If Exist "%~n0_%name%.bat" (
Call "%~n0_%name%.bat"
rem /* Initialise character save using predefined variables if character new */
) Else ( Call :Save )
rem /* Force Assignment of name variable */
) Else ( Goto name )
===============================================
::: Script body
::: End of Script
Goto :Eof
===============================================
:Save :# function
rem /* variation on magoo's method of saving */
(For /F "Delims=" %%G in ('Set #')Do Echo/Set "%%G")>"%~n0_%name%.bat"
Exit /B 0

T3RR0R
- 2,747
- 3
- 10
- 25