Page 1 of 1

how do i move lives to the next level

PostPosted: Fri Oct 21, 2011 11:58 am
by pikapika
hi, i want to know how to make it so that when it loads the next level in my game that the amount of lives that your character had in the previous level get transferred to the level your on now. please post an answer.

Re: how do i move lives to the next level

PostPosted: Fri Oct 21, 2011 1:00 pm
by foleyjo
When you create the lives variable you need to put it into a save group.
At the end of the level you use a saveVar and then at the very start of the next level use a loadVar

Re: how do i move lives to the next level

PostPosted: Fri Oct 21, 2011 4:05 pm
by pikapika
what exactly are load vars and save vars and how do i use them for this

Re: how do i move lives to the next level

PostPosted: Fri Oct 21, 2011 4:35 pm
by foleyjo
In level 1 create your variable and then put it in a save group for this example we will call it YourGroup

At the end of the level before you load the next level put this in your code

saveVars("yourfilename", "YourGroup");

This will save all the variables in the YourGroup group

level2 create the variable again with the same name and group and then use


loadVars("yourfilename", "YourGroup");

Re: how do i move lives to the next level

PostPosted: Sat Oct 22, 2011 9:40 pm
by HitoV
Its not too tough to do, I'll try and walk you through it.
You want to make a global variable for your lives. Make sure to make this one inside game editors built in variable creator. When you create it be sure to fill in something for the save group. For this example I am just going to use "lives" as the variable and "lvlstart" as the save group.

Put this in your level end code:
Code: Select all
saveVars("game.sav", "lvlstart");

This will create a save file int he main directory of your game called "game.sav" You can actually call it whatever the heck you want. The second argument is what save group you want to write in the game.sav file or which group you want to update if there is already a file present. In my particular game I have bombs, lives, and weaponstate as part of the save group "lvlstart."

When your new level starts, all you have to do is write a code to load the saved variables... just put:
Code: Select all
loadVars("game.sav", "lvlstart");

This will simply update all the variables in the save group to what they were previously saved as in the save file.