Verge 3 Write/ReadVars (Save Games)
Displaying 1-9 of 9 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
robert_boyd

So I've graduated from college, I now have a steady paycheck, I bought a new computer (on which Verge 3 and the utilities seem to work), I had a flash of inspiration last night of how a story idea I was thinking of would translate into some interesting gameplay mechanisms, I was inspired by Ustor's Cuddles game, and I'm ready to start serious work on a Verge 3 RPG. Woohoo!

Anyway, my question has to do with saving and loading games. I remember with Verge 2, this was a breeze: just use WriteVars to copy all the Global variables to a file and then use ReadVars to load them in. However, I was unable to find those two functions in Verge 3. Is there a similarly easy way to copy and load every global variable to a file or am I going to have to do this manually one variable at a time (the mere thought of all the work that would entail makes me ill).

Posted on 2006-06-03 20:28:18

CrazyAznGamer

From what I've seen, it's one var at a time.
Actually, that's not very bad, because it offers considerable amounts of flexibility. You load them in sizes you want, in any order, and you include/exclude what you want in save games. You could then, perhaps, isolate certain features (you know, such as interface, which can remain uniform while save files change).
So yeah, a lot more coding, but if you use it well, actually a lot better.

Posted on 2006-06-03 20:58:11

Overkill

Each variable at a time really isn't hard. Besides, Read/WriteVars() although useful, would screw up all the game resources stored in memory, and have access to some unnecessary data or data you wish to protect.

Here, read this: http://www.verge-rpg.com/docs/view.php?libid=1&section=25

Additionally, here's an example of how you could do your save functionality.

void SaveGame(string filename)
{
int i;
int f = FileOpen(filename, FILE_WRITE);
if (!f)
{
Exit("SaveGame :: Could not save game to file '" + filename + "'! What.");
}

for (i = 0; i < CHARACTER_TOTAL; i++)
{
// FileWriteString saves strings!
FileWriteString(f, character[i].name);

// FileWriteQuad saves ints as binary!
FileWriteQuad(f, character[i].hp);

// FileWriteWord saves smaller integers as binary!
// (word/short) (must be 0 - 65536, anything else will not be stored right)
FileWriteWord(f, character[i].mp);

// FileWriteByte saves tiny integers as binary!
// (byte) (0 - 256, anything else will not be stored right)
FileWriteByte (f, character[i].attack);
FileWriteByte (f, character[i].defense);
FileWriteByte (f, character[i].magic);
FileWriteByte (f, character[i].agility);
}

// Don't forget to close your file! I almost did.
FileClose(f);
}


And... you have to remember, most engines/languages require you to actually write each variable entry to disk anyway. Sure, it was in verge2, but things have changed since then, I'm guessing particularly how resource memory is handled. I think I used to use it, sure. But, I also distinctly remember tossing ReadVars()/WriteVars() away, because adding any changes to the variables in your verge2 VC files would destroy the save format for the game, and as a result there was no backwards compatibility whatsoever possible.

EDIT: Whoops. I meant to use FileWriteByte for attack and defense and such :D

Posted on 2006-06-05 15:33:17 (last edited on 2006-06-06 06:20:34)

robert_boyd

Thanks for the information. I feel really stupid - for some reason I was reading FileWriteQuad as writing 4 BITS not 4 BYTES and the thought of having to work with my data at the bit level was freaking me out. I'm feeling much better now. :D

And yeah, I remember how ReadVars()/WriteVars() had absolutely zero backwords compatibility if you changed variables around so I can see how this method is worth the extra hassle if only for that fact. Plus, it looks like it would be fairly easy to have a seperate system save file where you could store system configurations, unlocked main menu extras (like a New Game+) and the like.

Posted on 2006-06-05 21:53:29

mcgrue

4 bits would be FileWriteNybble()!

...

Posted on 2006-06-05 23:22:04

robert_boyd

So any plans on implement FileWriteNybble() in the next version? ;)

Posted on 2006-06-05 23:40:37

Overkill

...No! :D

Posted on 2006-06-06 06:21:07

mcgrue

He meant to say ye... no, wait, he got it right. :(

Posted on 2006-06-07 20:23:58

Overkill

However, if you want to pack small numbers into a single int/word/byte (like, perhaps boolean-style vars), bitfields are good.

I made my demo-recording in Snowball fast and small by compacting all 8 button states (b1, b2, b3, b4, up, down, left, right) into a single byte.

Writing:
FileWriteByte(demo_file, b1 + (b2 << 1) + (b3 << 2) + (b4 << 3) + (up << 4) + (down << 5) + (left << 6) + (right << 7));
Reading:
(note this would only work on my custom verge3 build, as the button variables are currently not writable in the official build)
j = FileReadByte(demo_file);
b1 = j & 1 == 1;
b2 = j & 2 == 2;
b3 = j & 4 == 4;
b4 = j & 8 == 8;
up = j & 16 == 16;
down = j & 32 == 32;
left = j & 64 == 64;
right = j & 128 == 128;

Posted on 2006-06-08 14:15:01 (last edited on 2006-06-08 14:22:12)


Displaying 1-9 of 9 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.