saving with C++

Started by
13 comments, last by izua 17 years, 4 months ago
i posted this before, but my thread got lost b4 i got to read it, how do i save using C++? I want to be able to save on my game, but I don't know how to make it save, plz help articles apreciated the types of saving i am interested in is saving to a server or in a cookie form
Advertisement
what type of game is it?

you can do it two ways, if it has accounts, and it's a server side script (you mention cookies), just make a file with the account name, and write in it whatever data you'll need to "reload"

if it's a client-side script, like &#106avascript, write the same info into a cookie ( i doubt someone will permit you write-access on their hdd). the only problem here is that users might be able to alter this data. it won't matter if the game is singleplayer.

but do provide additional details :)
If you are trying to save to cookies, reconsider the language you are using. While its possible to accomplish in C++, it's far better to use a language designed for this job, like PHP.

I'm not sure what kind of game you are writing, but if its a browser based game, you wouldn't use C++ anyway.
basicly i am making non graphics (at least for now) C++ games that my friend is putting on his site, he has his own server, so that isn't a problem

at the moment the games are singleplayer, but in the future i will be looking into multi

i am more interested in saving to a server than cookies, because in the end it will be what i will be doing (at least until i get into college and start some real programming)

please include (if you can) where i can find how to do it (articles, ect)
If you want to send data over a network, look into a network library. Google should help here.

Quote:games that my friend is putting on his site, he has his own server, so that isn't a problem


By that do you mean he is putting them on his site, to make them available to download? If so, then this has nothing to do with what you were saying before, i.e. transmitting data over a network.
um, look. if you make it in c++, you will end up (theorethically) with an optimized desktop app. that means, it's run into the computer of the end user.

but if you want to save to the cookie, you'll need a completly different approach. the game should be played in the browser, and it will send some headers with cookies when needed.

ofc, you can do this in c++, but you'll have to build first another layer, the http one, to handle connections, requests, etc, and i'm sure that's not what you want. i'd suggest you look over wikipedia at least, for differences between php and c++. you might be wanting php and not even knowing it :)

but do tell me more about the game.

izua
If you are making a dos based game, you can just do some simple file reading... like say there are 5 levels to a game... when the game loads make it where it will read the file you are writing to and see what level they are at, and then check how many lives and health they have... then just use a simple cout << function to output the stuff they were at.

EDIT:: Sorry didn't read about the cookie thing.. not sure how to do that ;P
So what we're looking at is a server/client text-based game (Singleplayer of course)

If this is the case, we won't need an external server for our Single Player game. It would just be simple to read/write the save data on to your own hard drive.

To save a file I'd imagine you would just have a simple function to get the player and level data you need to keep so you can reload this next time the game starts.
Examples of these permenant data pieces would be:
Player Name
Player Inventory
Player Statistics (level, beneficial attributes, non-benefitial attributes, etc..)

These are the ONLY things you'll want to keep.
So... say we have something like this:
player_name = some_value; player_inventory = some_value(s); //you would most likely be dealing with an array of some sort to keep track of inventory itemsplayer_statistics = more_values;


to get the value of these variables you would do
get_player_name(){    return player_name;}get_player_inventory(){    return player_inventory;}etc........//then we would do the save function where we write into the file the variables we just grabbed//we'll need a way to load the values into their variables again. This is where set_variable_name() will come in...set_player_name(){    player_name = load_player_name;     load_player_name = NULL;     }set_player_inventory(){    player_inventory = load_player_inventory;     load_player_inventory = NULL;     }etc...//all-in-one load function to wrap all set_ functions into oneload_game(){    set_player_name();    set_player_inventory();    set_player_statistics();}blah blah file read/write codewriting in to the filecout << get_player_name();cout << get_player_inventory(); etc....loading the files cin >> load_player_name;cin >> load_player_inventory;  etc...Resetting the variables to last saved... load_game(); 


now, it's been quite a while since I've done any programming so even this semi-psuedo-code can be wrong in the method I've gone about doing this.

You'll need to be able to save files server side when you eventually go Multiplayer with this game to keep users from cheating and tampering with their data.
gratz to all! youve come up witht he most complex answers without actually answering the question!
i need to know how to save it to a server, not how to organize it so it will be ready to save to it
i need syntaxes ect, or articles about it!

The organizing part is a MUST to know if you want to be able to save and load anything. If it's not organized your functions wont work properly.

If you want info about cookies go the Web Development forum we have on the main forum page or go to here

This topic is closed to new replies.

Advertisement