how do i move lives to the next level

Non-platform specific questions.

how do i move lives to the next level

Postby pikapika » Fri Oct 21, 2011 11:58 am

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.
pikapika
 
Posts: 10
Joined: Wed Oct 12, 2011 12:06 am
Score: 0 Give a positive score

Re: how do i move lives to the next level

Postby foleyjo » Fri Oct 21, 2011 1:00 pm

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
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: how do i move lives to the next level

Postby pikapika » Fri Oct 21, 2011 4:05 pm

what exactly are load vars and save vars and how do i use them for this
pikapika
 
Posts: 10
Joined: Wed Oct 12, 2011 12:06 am
Score: 0 Give a positive score

Re: how do i move lives to the next level

Postby foleyjo » Fri Oct 21, 2011 4:35 pm

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");
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: how do i move lives to the next level

Postby HitoV » Sat Oct 22, 2011 9:40 pm

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.
HitoV
 
Posts: 48
Joined: Sat Aug 27, 2011 8:22 am
Score: 3 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest