Sign in to follow this  
esperknight

Question about coding save/load game feature

Recommended Posts

I've been looking for a while on how to do this but I haven't seen any definite way. My idea (using how I did my engine I should say :) is to have it basically scripted like the actual script files it uses. The way I have it, a file gets loaded in to a vector, runs through each line to see the command and executes based upon it. My prob. is, is how the text work. It uses the text as a stopping point for events. Basically when it hits it, it loops until it sees a mouse click. I'm thinking if the menu is accessed within this, I can pass in the same vector it uses to load the data, and just modify that vector through a pointer that way when it gets out of the text loop it will just execute from there and it'll have a command to set the position and a jump command where it will load up the script it needs to load from. (Hopefully I'm making sense ;) My question is, is this a practical way of doing it? Or should I go about it differently? Also, I'm not using classes yet, just straight functions and no global variables (can't seem to get them to work without it say multiple inclusions :). Hopefully this makes sense, if need be I don't mind posting the code (although it might be a tad messy, plus uncommented ;). I appreciate all the help! Thanks! EsperKnight

Share this post


Link to post
Share on other sites
It mostly depends on what kind of game/datastructures you are saving.
For a game like Doom3, you nned to save equipment, position.. and what triggers have been triggerd, plus any monsters states if there are any.

Your way seems.. complicated. ;)

I have been involved in 2 "real" games load/save code.
Game #1) Lots of objects and triggers, all needed to be saved differently. Each object that needed saving inherited from a save/load interface, each object had an unique ID, and when the game was saved, each object:s save function was called, and it saved what it needed. Then when a game was loaded, after all init code had been run, load was called for all objects.

Game #2) More like chess... each "command" is saved, so a savegame consist of all moves that has been made in the current game. When loaded, it just quickly goes through all the moves.

If you are using Python/Lua it get's even easier, then you can just dump the current state to file and later just load it.

Good luck!

Share this post


Link to post
Share on other sites
Hmmmmm, if you have scripting system up and running, then IMHO it's good idea to use it, when saving / loading game. If I have understood correctly, your only problem is that, when you're executing such script, many commands tend to be too much... interactive? :-) Maybe try adding some conditional flag, which will say: "ok, now you can execute such-and-such interactive commands."?

If it's not beyond your practical skills (sorry, I don't know how much do you know programming, and information that you're "not using classes yet, just straight functions and no global variables (can't seem to get them to work without it say multiple inclusions :)" says to me, that you're rather new C++ programmer ;-) ), I would suggest using XML file for saving things. I can give you sample format of XML file saved on disk, if you want :-)

Keywords to Google:
XML
XML GameDev <--- there are some good tutorials here on GameDev about XML
TinyXML <--- if you decide to actually use it, XML parsing library


Share this post


Link to post
Share on other sites
Gulgi: The second one sounds like what I might have to do, basically save it as a script file and just have it run through it and continue with the real one :) Also, I wish I started of learning Python or Lua, might've made my life easier but I decided to code my own, which I'll admit, helped me learn a lot :) (Only redid it 5 times so far :D )

Koshmaar: Well, techinically what your saying is right it's just not completely right but that's because I didn't explain enough :) The game is a basically a choose your own adventure (really a Visual Novel, but the other describes it better). The only real point it allows the menu to load is during the text since thats the only interaction needed on the users part, or the choices too but I might not allow saving during then since it kind of seems unfair :) What I would love to do is have some global variable to modify but I keep reading it might not be the best idea (I guess if I made sure to document it and be careful should be alright). I'm using Dev-C++ which really shouldn't matter but I'm noticing it not recompiling sometimes when it's supposed too. I've tried using export in such but when including the header file, it gives me the multiple inclusions error and I'm also using the ifndef stuff too. (You know I just realized I'm prob. branchign off from my previous post, ah well ;) What I thought of doing is, just pass in the original vector that holds all the script data by pointer so the text loading code can modify it if a load happens, then when it exits, it should be able to continue from there and execute from that point (of course resetting the position also). My thinking is, globals should be the way to go for this for ease of use and readibility but it's not working. Ah well :) Also, before I go off topic to much, I wouldn't mind seeing the save file to see how it looks, might give me more ideas :)

Also, a question for anyone, I know theres so many ways to one thing in C++, but, would it been easier to just create a main class and branch from it (inherit I should say) to allow easier manipulation? Or should I even bother if its only going ot make things more easier and readable?

Thanks for the replys!

EsperKnight

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this