Computing.Net > Forums > Programming > Batch File Save Game

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Save Game

Reply to Message Icon

Name: jcgun
Date: June 1, 2009 at 15:33:03 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

hello.
i've had an idea for a RPG batch file, and i think it could work, except for one thing.

everytime you open the game, you'd have to start from scratch. would it be possible to save the game internally or externally??



Sponsored Link
Ads by Google

Response Number 1
Name: MikeKozar
Date: June 1, 2009 at 18:03:10 Pacific
Reply:

It should be entirely possible, although it could be some work.

The most straightforward way would be using something
simple like:

ECHO %GAMESTATECODE% > SaveGame.txt

and then reading from that code to restore progress...

SET /p GAMESTATECODE= <SaveGame.txt
IF "%GAMESTATECODE%"=="ProgressLevel3" goto Level3

I suppose you could have several files, or use some more
advanced parsing data, to capture multiple variables (score,
hitpoints, etc) for a more complete restore.



0

Response Number 2
Name: reno
Date: June 1, 2009 at 22:03:56 Pacific
Reply:

D:\batch>set $score=100

D:\batch>set $hitpoints=80

D:\batch>set $
$hitpoints=80
$score=100

D:\batch>set $>savegame.txt

D:\batch>type savegame.txt
$hitpoints=80
$score=100

D:\batch>set $hitpoints=&set $score=

D:\batch>set $
Environment variable $ not defined

D:\batch>for /f "tokens=*" %a in (savegame.txt) do set %a

D:\batch>set $hitpoints=80

D:\batch>set $score=100

study this, and you will get the idea
to save game currentstate: set $>savegame.txt
to load game state: for /f "tokens=*" %a in (savegame.txt) do set %a


0

Response Number 3
Name: jcgun
Date: June 2, 2009 at 10:20:02 Pacific
Reply:

Thanks!
to tell you the truth, i'm not understanding reno's answer, but I like the Mike's answer. It is more of 'my style'.

Obviously, there are going to be several stats. is it possible to put them all in one document, rather than having a doc for every stat.


0

Response Number 4
Name: Razor2.3
Date: June 3, 2009 at 15:53:00 Pacific
Reply:

is it possible to put them all in one document, rather than having a doc for every stat.
Yes. Adopt reno's "style."


0

Response Number 5
Name: MikeKozar
Date: June 3, 2009 at 16:17:31 Pacific
Reply:

Reno is using the same basic moves I am, but with
significantly more sophistication.

Rather then using ECHO to send each stat value to a text file
individually, he is using the SET command combined with a
known value for the first letter of the variable. Entering

SET $

...as in his example will produce the value of every variable
that starts with a $. (Read "set /?" for more info on why this
works)To clarify, you could get the same results if you called
your variables STAT_HP, STAT_GOLD, STAT_MANA and
ran

SET STAT_

...you would get a friendly list of every stat in one command.

By redirecting this output to a text file, as Reno has done,
you get all of your stats saved in one move.

Reading them back from this file involves a FOR loop...which
I'm still getting the hang of. However, the plaintext of his FOR
command is that for every line in "savegame.txt", run a SET
command with the value of that line. So if the first line is
$hitpoints=80, the command will output

SET $hitpoints=80

...and then repeat the process for every line.

I hope this helps explain what Reno was talking about; If you
can get it going it's a very good solution to your problem.

~Mike


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Save Game

Batch File Test www.computing.net/answers/programming/batch-file-test/17238.html

write, save & run a batch file www.computing.net/answers/programming/write-save-run-a-batch-file/17547.html

Batch file to find ip and host name, and save www.computing.net/answers/programming/batch-file-to-find-ip-and-host-name-and-save/19455.html