How to make a game saving system?
Posted: 03 May 2021 22:32
Hi there, can any of you help me on how to make a game saving system in a .bat RPG game? I am new to this site so sorry if I'm breaking the rules. Thank you very much.
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
call :init
call :debug
call :save
set "value1=D"
set "value2=E"
set "value3=F"
call :debug
call :load
call :debug
goto :eof
:debug
set "value1"
set "value2"
set "value3"
echo(===
echo(
goto :eof
:init
set "value1=A"
set "value2=B"
set "value3=C"
goto :eof
:save
>"game.sav" (
set "value1"
set "value2"
set "value3"
)
goto :eof
:load
<"game.sav" (
set /p "value1="
set /p "value2="
set /p "value3="
)
goto :eof
Code: Select all
@Echo off
rem /* predefine your key variables prior to this loop */
:login load existing or create new
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 login )
===============================================
::: Script body
::: End of Script
Goto :Eof
===============================================
:Save function
(For /F "Delims=" %%G in ('Set #')Do Echo/Set "%%G")>"%~n0_%name%.bat"
Exit /B 0