1

I've seen it done before on someone else's Batch program, so I'm sure it's possible. Every time I launch my program I run a series of lines of code such as:

set/a num=0

set/a tog=1

set/a ran=%random% %%10 +1

However, I would like for certain variables to stay around, even after the program is closed. I need scripts that can:

  1. Write in a separate document the values of certain variables
  2. Check that document for values at any point in any usage session

Thanks in advance!

10
  • Duplicate of stackoverflow.com/questions/5898131/… Commented Jun 28, 2015 at 20:50
  • @AVee I read that question and it doesn't seem to answer my request. That or I'm not good enough at Batch to understand Commented Jun 28, 2015 at 21:03
  • Also worth noting that as long as the command prompt that the script runs in stays open, the variable will also be available. So instead of double-clicking the script, open the command prompt, cd to wherever it is, and then run your script from there and just never close the command prompt. Commented Jun 28, 2015 at 21:05
  • And look at the answer under the accepted answer in the other question. As long as you don't need /a or /p (and you only need /a when you're doing math with variables, not when you're setting variables to numbers), then you can just use setx instead of set. Commented Jun 28, 2015 at 21:09
  • @SomethingDark I need the make a folder of files that I can download onto someone else's computer and it will work without any instructions. I want it to be user friendly enough that they can just run a .bat and not have to worry about anything. I just need a permanent memory file so that when they turn off sound effects or turn off animations, it will remember their preferences next time they run the .bat Commented Jun 28, 2015 at 21:11

1 Answer 1

3

You need a save system like so:

( echo %VARIABLE1% echo %VARIABLE2% echo %VARIABLE3% echo %VARIABLE4% echo %VARIABLE5% ) > LOGS.prgmsav 

The file extension can be .txt or something weird like .nerfguns, to load LOGS.prgmsav:

< LOGS.prgmsav ( set /p VARIABLE1= set /p VARIABLE2= set /p VARIABLE3= set /p VARIABLE4= set /p VARIABLE5= ) 

The VARIABLE is any variable, you can save as many as you want! I hope I helped!

Sign up to request clarification or add additional context in comments.

1 Comment

No problem, I'm just happy to help :D!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.