Carrying over health to the next level

Hi i just want to know if there is a way to carry over health from level to level for example i pick up a health pack then i get spiked and go to next level the code just restets. how can i make it save the health.

3 Likes

Yeah, you can use the Save behavior. Whenever the health value is changed, save it, and whenever you start a new level, read the saved value and set the health accordingly

Combine the Coin and Health options.

Great explanation. Here have a link with barely any context

lol

Can you please give me an example

The saving behavior can be the most helpful, yet the most painful behavior to use. I would show some sort of an example, but I could explain a little more on the behavior and hopefully it helps.

So the Save behavior acts very similar to the global, but this saves numbers while the player is online. So it acts like a number for inputs and outputs.

For saving health you could make it so that at the end of each level, when you trigger the next level, it will save the players health into the save behavior. Then on the second level, have a object or some sort of trigger to send a message on start to the player so it will read the save behavior and then output that number and SET the number that is the players health. This can be quite tricky since you can accidentally make looping codes and that crashes your game. But it works really well when you get it working.

Iā€™m not very good at explaining stuff, but Iā€™m sure @JR01 would be more than welcome to explain this in much more detail. That is if you are still confused.

1 Like

Thank you @ManiacPumpkin for the help ill ask @JR01 for help because it is quite confusing.

1 Like

I went into great detail on how to use save behaviors here: I need some help with my points system to save

But in simplified terms, when you put a number into a save behavior, you can use it later. It will save across any level and even if you leave the game.

Just set a name for the save block, and then save a number to it. Use the load input to output the saved number.

Be warned, the save and load inputs will give an ouput, so make sure to not loop the same save block or it can crash the game on play.