Solved need help with batch loading variables from a file

October 18, 2013 at 12:52:33
Specs: Windows 7
ok so I have 3 or more variables named hp, money, and exp. could anyone tell me how to take the numbers of the variables from a file such as "saveload.dll" and put them in for the variables...simply...im not the brightest when it comes to batch programing.

I have this so far for saving them to a file

::====start=====
::====variables so far=====
set /a hp=100
set /a money=50
set /a exp=0
goto home

:home
cls
would you like to save?
echo 1)yes
echo 2)no
set /p home=
if %home%== 1 goto save
if %home%== 2 goto home
:save
cls
(
echo %hp%
echo %money%
echo %exp%
)>saveload.dll
goto home

::====end====

please help with loading the variables!


See More: need help with batch loading variables from a file

Report •


#1
October 18, 2013 at 19:02:02
✔ Best Answer
One way, but probly not the best:

:save
cls
(
echo set hp=%hp%
echo set money=%money%
echo set exp=%exp%
)>saveload.dll
goto home
...
:load
move /y saveload.dll saveload.bat
call saveload
move /y saveload.bat saveload.dll
::========== end batch snippet
There are other examples in this forum, but I'm too lazy to dredge them up.


Report •

#2
October 19, 2013 at 11:16:58
That's really strait forward nbrane.

edit: note that was intended as a compliment

::mike

message edited by mikelinus


Report •

#3
October 21, 2013 at 11:53:50
thanks guys...as a side note how would one had something like a thirst variable or hunger variable that is constantly changing throughout the game

Report •

Related Solutions

#4
October 28, 2013 at 10:49:02
::====start=====
::====variables so far=====
if exist saveload.bat goto home
set /a hp=100
set /a money=50
set /a exp=0
goto home

:home
CALL saveload.bat
cls
would you like to save?
echo 1)yes
echo 2)no
set /p home=
if %home%== 1 goto save
if %home%== 2 goto home
:save
set /a hp=100 >saveload.bat
set /a money=50 >>saveload.bat
set /a exp=0 >>saveload.bat
goto home

::====end====

Note the one ">" while the rest have two just makes it so
the files overwrite and you don't have masses of variables clogging the file that
you are saving too. To get the variables set in another batch file or the same after you reload it use the command
call. Its best to use this at the start of a batch file
Example:
call saveload.bat
And I changed the type of file you are saving to into a .bat because dll's are a pain for me. Don't ask why!

~Waffa


Report •

Ask Question