Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How do I make a save file?  (Read 3602 times)

0 Members and 1 Guest are viewing this topic.

Luigi master

    Topic Starter


    Rookie

  • I'm a pretty good coder, but not the best.
  • Thanked: 1
    • Luigi master
  • Experience: Expert
  • OS: Other
How do I make a save file?
« on: June 11, 2016, 12:32:59 PM »
omg first post
For my game, I want to make a save file.
I already have this code:
Code: [Select]
(
  echo %Name%
  echo %HP%
  echo %LV%
) > %Name%Save.lsav
to save.
How do I make the batch file read each line?
Please help!
« Last Edit: June 11, 2016, 12:54:04 PM by Luigi master »
I have a website so yeah
vvvvvvresource.byethost6.com

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: How do I make a save file?
« Reply #1 on: June 11, 2016, 12:47:04 PM »
The > redirection operator has an opposite operator the < to pass from file back to the variable.

http://stackoverflow.com/questions/3068929/how-to-read-file-contents-into-a-variable-in-a-batch-file
Quote
Read file contents into a variable:

for /f "delims=" %%x in (version.txt) do set Build=%%x

or

set /p Build=<version.txt

Both will act the same with only a single line in the file, for more lines the for variant will put the last line into the variable, while set /p will use the first.

Using the variable – just like any other environment variable – it is one, after all:

%Build%

also more here on this: http://www.robvanderwoude.com/redirection.php

Luigi master

    Topic Starter


    Rookie

  • I'm a pretty good coder, but not the best.
  • Thanked: 1
    • Luigi master
  • Experience: Expert
  • OS: Other
Re: How do I make a save file?
« Reply #2 on: June 11, 2016, 12:55:36 PM »
Okay, let me rephrase.
How do I make it read every line?
I want this:

Save File:
1234
4321
1324

Now in the batch file:
(Sets the variables to the line)
%Line1% = 1234
%Line2% = 4321
%Line3% = 1324
I have a website so yeah
vvvvvvresource.byethost6.com

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: How do I make a save file?
« Reply #3 on: June 15, 2016, 12:59:43 PM »
Okay, let me rephrase.
How do I make it read every line?
I want this:

Save File:
1234
4321
1324

Now in the batch file:
(Sets the variables to the line)
%Line1% = 1234
%Line2% = 4321
%Line3% = 1324

There are many ways to skin this cat:   using this format when creating the save file allows you to rename the .lsav file and add a .bat extension, which you call and rename the file back again.  All your variables are set.

Code: [Select]
(
  echo set name=%Name%
  echo set HP=%HP%
  echo set LV=%LV%
) > %Name%Save.lsav

DeScripter



    Starter

    • Experience: Familiar
    • OS: Windows 7
    Re: How do I make a save file?
    « Reply #4 on: April 03, 2017, 01:36:16 PM »
    I'm not sure this topic was resolved, or if the OP found it helpful. To reiterate what Foxidrive said with an example:




    :save
    (
    echo %health%
    echo %bees%
    )>textfile.txt


    :load
    (
    set /p health=
    set /p bees=
    )<textfile.txt

    Use "Echo" to set the variable, "set /p" to load it. Also NOTE the direction of the carrots. ">" to save, "<" to load. Hope that helps!