Jump to content
  • Advertisement
Sign in to follow this  
alway616

saving with C++

This topic is 4248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 javascript, 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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 items
player_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 one
load_game(){
set_player_name();
set_player_inventory();
set_player_statistics();
}

blah blah file read/write code
writing in to the file
cout << 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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!