How to apply a text file with multiple variables to the batch console -
okay have batch program writes character's stats txt file when save game. unable load stats properly. thought maybe if saved them console commands , syntax use type command , run commands setting variables on console ones in txt file. there simple way writing of variables txt file reverse?
sample code of variables being written:
if not exist "%~dp0\users" md "users" ( echo set charname=%usercharacter% echo set level=%level% echo set health=%health% echo set expcap=%expcap% )> "%~dp0\users\%usercharacter%.txt" see wrote text file thinking load file , set variables file had.
didn't work. if have questions ask. can't post pictures right think got point across.
you're close. instead of type, run text file through loop.
for /f "usebackq delims=" %%a in ("%~dp0\users\%usercharacter%.txt") %%a the set commands have automatically run.
how works
for /f loop takes in command, file, or string (in case, file) , processes output of thing line line.
the usebackq tells for loop thing in quotes file - ordinarily, quoted string passed for /f loop treated string instead, since have space in path, needs quoted loop doesn't throw error.
delims= tells loop not delimit (split) each line in file. ordinarily, line split on whitespace - spaces , tabs.
%%a variable containing first delimited token in string. however, since told loop not delimit string, %%a contains entire string.
"%~dp0\users\%usercharacter%.txt" file.
do tells loop after rest of code block (either rest of line or between ( on line , first ) on lower line) should performed while loop still ongoing.
%%a in case set command have stored in text file. because of how batch replaces , evaluates text, running commands have stored!
Comments
Post a Comment