RobinTendo wrote: ↑18 Feb 2021 07:37
When I go to :loadgame, the file just closes. Does anyone know what I did wrong?
(probably everything tbh)
At least in the code you posted, there is nothing wrong.
But you might improve your code in various ways:
- Start a command with a redirection to protect your code from adding spaces at the end of redirected text.
- Use doublequotes around filenames to avoid errors with filenames that contain spaces.
- Use doublequotes around set parameters ('set "a=1"' instead ' set a=1').
- Encapsulate functionality into functions and call them (instead of using a single giant function), which improves readability of your code (which helps you to keep track of your program flow)
- Avoid using unneccessary files, so you should use only one savegame file (for each single savegame).
Eureka! wrote: ↑19 Feb 2021 05:52
So choose your variable names wisely
Better use safe code and avoid using code that can go wrong.
The easiest way should be to use batch files for savegames; sth like the following (untested):
Code: Select all
@echo off
setlocal enableExtensions enableDelayedExpansion
set "money=100"
set "story=interesting"
set "name=default"
for %%a in ("money" "story" "name") do echo("%%~a=!%%~a!"
echo(===
set "savegame=savegame1.bat"
call :save savegame
for %%a in ("money" "story" "name") do set "%%~a=sth different"
for %%a in ("money" "story" "name") do echo("%%~a=!%%~a!"
echo(===
call :loadgame savegame
for %%a in ("money" "story" "name") do echo("%%~a=!%%~a!"
goto :eof
:save
>"!%~1!" (
for %%a in ("money" "story" "name") do echo(set "%%~a=!%%~a!"
)
goto :eof
:loadgame
call "!%~1!"
goto :eof
penpen