Newbie Asks: How to Save in Multiple level game

Non-platform specific questions.

Newbie Asks: How to Save in Multiple level game

Postby ggesterGamePro99 » Mon Apr 16, 2012 9:35 pm

I'm a newbie but i have some game programming experience from before and i've played games, and i know about games and stuff(not much but so so)
ANyways, basically

I'm making a multilevel game. How do i save it so that the user can start where he left off, at the level where he left off.

I could go as far as to also say..what if i have a game where the user collects a bunch of stuff and has earned money or something and i want him to when he comes back to his game days or hours later to start the game and start off with all the items and money he had last time. So how do you save that too.

I'm guessing you would write some kind of text file teeling which level you save at..and to also write all your score and items and money into that text file. Right?

But how would i do it?
ggesterGamePro99
 
Posts: 44
Joined: Mon Apr 16, 2012 1:53 am
Score: 0 Give a positive score

Re: Newbie Asks: How to Save in Multiple level game

Postby skydereign » Mon Apr 16, 2012 11:35 pm

To save you can either use gE's saveVars/loadVars functions, or use FILE* operations. I'd suggest using saveVars and loadVars since you are just starting out. Essentially you create variables and put them into a save group. If you wanted to save score, you would create a score variable, and put that into a savegroup, for instance "player_save". You can add other things to the save group, such as a variable that holds the player's life, and perhaps an array to hold items obtained. Then to save, put this code into whatever event saves your game.
Code: Select all
saveVars("save_file", "player_save");

Then when you start the game (want to load the save), you do the reverse operation.
Code: Select all
loadVars("save_file", "player_save");
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron