Sign in to follow this  
alway616

saving with C++

Recommended Posts

alway616    122
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
izua    152
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
scorpion007    118
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
alway616    122
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
scorpion007    118
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
izua    152
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
nooblet    167
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
caldiar    715
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
alway616    122
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
caldiar    715

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
KulSeran    3267
Try a site like: Beej's Networking Guide.

It kinda sounds like you are more concerned about learning how to set up a client-server archetecture,
"as-if" you are making a multiplayer game. That site should show you the basics you need to set up a
client-server protocol you can use to send you data to the server. The server in turn should then use
standard file io (fstream/FILE*) to put the data on the server's diskdrives.

Expanding on what exactly your program is/does and the end goals will help people to give you
more tailored information. Because there is "a way" "the easy way" and "the hard way" for doing everything.
And we(the community) don't know if you are set on "the hard way" because you dont understand what you are
doing, or if you want "the easy way" of doing something you didn't explain well that you were trying to do.

[Edited by - KulSeran on November 29, 2006 5:52:13 PM]

Share this post


Link to post
Share on other sites
DvDmanDT    1941
When someone plays your game, he plays it on his computer. Normally, you save the game on his computer. If you want to save it on a server, you'll need to make your game connect over the internet to the server, then tell the server what you want it to remember. The server must have some program installed on it (which you'll have to create too), that knows how to save something on that computer.

To save something on the computer the game is ran at, loopup fopen(). It'll let you save to a file. It won't, however, let you save your game on another computer (a server), and there is no simple way of just doing that.

Share this post


Link to post
Share on other sites
JBourrie    1204
You are looking for a magic bullet that doesn't exist. If you insist on server-side storage (which seems bizarre for a singleplayer game) then you need to make a server-side program that can accept save requests and handle file organization, and then in the client you need to set up a network connection with the server. This is all explained in the network guide linked above.

People are answering your question with very valid and useful help. It is you that refuses to listen. Please learn to control yourself and think about other peoples ideas before you dismiss them.

Share this post


Link to post
Share on other sites
Palidine    1315
What you save and how you save depends entirely on your own specific game. Saving means saving state. state means things that are different between frames and things that are important and meaningful to the game world.

For instance for a typical game entity you'd save things like:

current hitpoints
AI state (moving, shooting, etc)
facing angle
current velocity

Now the _what_ you save is entirely up to you.

The _how_ you save is using "binary file I/O". You can google that phrase for code.

The basic algorithm of saving is this:

User Clicks save
Game iterates all objects that need to be saved
for each object dump it's type and it's data to the file stream
after iterating all objects close the file stream.
data is now saved in some file on the HD.


User clicks Load
Game opens the save file
game processes the save file re-instancing every object that needs to be created
as it's instancing each object it loads the saved data into that object

-me

Share this post


Link to post
Share on other sites
izua    152
I think i got it.
So you want a single-player desktop game with server-side saving..

here's what i'd do if i'd go for easy code:

client side - curl. Maybe i even encrypt the data in a simple way.
server side - apache and php, driven by mysql. (well, it's easy). There should be some hidden form, to where curl will post the savedata, and php will handle it to mysql. you'll need to take some additional measures to prevent hacking.

another way is to go straighforward with classic networking, but it's not as easy as curl. or you can try sdl_net :)

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