saving Health bar value when hit a spike and restart

How to make the game save and load the value of the health bar when it restart after I hit a spike?
I mean I want the game to restart the current level if I hit a spike, in same time to keep the health bar low.
I hope its clear. :slight_smile:

Thanks

Game Link
http://flowlab.io/game/play/760868

@CrimsonBlackGames has been using save a lot. He knows more about it than I currently do. I would guess that let’s say you have this set up:

Collision — -10 — (+)number[100] — bar
Connect the number[100] to (save) and once to (read)
Connect the save behavior to (set)(in)number[100] and when you die, it will once the number it was last on and set the 100 to like 50 or whatever and send it to the bar

Saving is an interesting behavior. Instead of saving everything (as is) for loading later, it saves an integer, or number…

If you want a number (such as a highscore) or something to carry over from one game session to another, you can use the save command.

In this case, you want the level to restart- but you want to save the value just before the level restarts, and have it read at the beginning of the level.

So, in this case, I would try to find a workaround, like sending the value to a GUI object (it will be out of the way) that stays between levels, and sends the health value back to the player instead of saving the value, because it carries the biproduct of keeping the value even when the game is refreshed, closed and opened, etc. I think you get the idea…

Anyway, use a message to send the value to the GUI object, and have the GUI object send it back at the beginning of the level Via a Once- if that makes sense.

Mhx Ar , CrimsonBlackGames
what you’re saying making a lot of sense , but unfortunately its not working (or maybe am not doing it right) I’ve been working on this for 2 days now :frowning:
I guess I have to keep trying …
anyways thanks

Oh wow, I just tried it myself and crashed the game.
Okay let me try this a different way.

This should be what you want. Create a new behavior bundle and paste this in there, then delete your old bar and collision, and try this. It sets save as 6 and loads the number, so the other 6 sets this 6 which saves and loads. It’s not my best attempt but it’s the only way I can get it to work without crashing, since you insist on having the level restart on collision.

[spoiler] {"behavior":{"links":[{"output_id":"d9e714d90931e148o0","input_id":"e3844a74f3352a41i0"},{"output_id":"e384ce1ca9643a42o0","input_id":"e3844a74f3352a41i1"},{"output_id":"e3844a74f3352a41o0","input_id":"e384375498783142i0"},{"output_id":"d9e58a24f79a0c41o0","input_id":"d0567e2a22939542i0"},{"output_id":"d9ea2ed0ee051c43o0","input_id":"d0567e2a22939542i0"},{"output_id":"e384ce1ca9643a42o0","input_id":"e3852b184b079144i0"},{"output_id":"e2d90229e6af3b41o0","input_id":"d9e714d90931e148i1"},{"output_id":"e384ce1ca9643a42o0","input_id":"e3852b184b079144i0"},{"output_id":"e3852b184b079144o0","input_id":"e384375498783142i1"},{"output_id":"d9e58a24f79a0c41o0","input_id":"d9e614a44dfdbb4ci1"},{"output_id":"d9e58a24f79a0c41o0","input_id":"d0567e2a22939542i0"},{"output_id":"d9ea2ed0ee051c43o0","input_id":"d9e614a44dfdbb4ci1"},{"output_id":"d9ea2ed0ee051c43o0","input_id":"d0567e2a22939542i0"},{"output_id":"e3852b184b079144o0","input_id":"e384375498783142i1"},{"output_id":"e384375498783142o0","input_id":"d9e714d90931e148i0"},{"output_id":"e384375498783142o0","input_id":"d9e714d90931e148i1"},{"output_id":"e384375498783142o0","input_id":"d9e714d90931e148i0"},{"output_id":"e2d90229e6af3b41o0","input_id":"d9e714d90931e148i1"},{"output_id":"e384375498783142o0","input_id":"d9e714d90931e148i1"},{"output_id":"d9e614a44dfdbb4co0","input_id":"d9e714d90931e148i2"},{"output_id":"d9e714d90931e148o0","input_id":"d9e90c50fdca644ai0"},{"output_id":"d9e614a44dfdbb4co0","input_id":"e38608dd233dd448i0"},{"output_id":"e38608dd233dd448o0","input_id":"e385a60c49088a4ci0"},{"output_id":"e38608dd233dd448o0","input_id":"e385a60c49088a4ci0"},{"output_id":"d9ea2ed0ee051c43o0","input_id":"d9e614a44dfdbb4ci1"},{"output_id":"d9e58a24f79a0c41o0","input_id":"d9e614a44dfdbb4ci1"},{"output_id":"d9e614a44dfdbb4co0","input_id":"d9e714d90931e148i2"},{"output_id":"d9e614a44dfdbb4co0","input_id":"e38608dd233dd448i0"},{"output_id":"d9e714d90931e148o0","input_id":"d9e90c50fdca644ai0"}],"nodes":[{"x":-1440,"id":"e3844a74f3352a41","tag":"","startVal":6,"inputCount":3,"group":"","behaviorType":"logic.logic.Value","outputCount":1,"name":"Number","y":64},{"x":-1260,"volume":100,"sound":null,"inputCount":3,"group":"","behaviorType":"logic.components.SoundEffect","outputCount":3,"url":null,"name":"SoundEffect","loop":false,"y":480,"soundURL":"/effects/pop/DM-CGS-32.wav.mp3","id":"d0567e2a22939542","soundName":"pop 2"},{"x":-1620,"id":"e384ce1ca9643a42","resetOnLevelStart":false,"inputCount":0,"group":"","behaviorType":"logic.triggers.Once","outputCount":1,"name":"Once","y":64},{"x":-900,"id":"e2d90229e6af3b41","inputCount":0,"group":"","behaviorType":"logic.triggers.Always","outputCount":1,"name":"Always","y":192},{"x":-1440,"delay":10,"id":"e3852b184b079144","inputCount":3,"group":"","behaviorType":"logic.triggers.Timer","outputCount":1,"count":1,"name":"Timer","y":-32},{"x":-1440,"inputCount":0,"group":"","behaviorType":"logic.triggers.Collision","collisionFilter":15,"name":"Collision","y":224,"targetClassId":3518354,"outputCount":1,"collideWithEntity":false,"id":"d9e58a24f79a0c41","targetEntityId":0},{"x":-1530,"inputCount":0,"group":"","behaviorType":"logic.triggers.Collision","collisionFilter":15,"name":"Collision","y":448,"targetClassId":3518394,"outputCount":1,"collideWithEntity":false,"id":"d9ea2ed0ee051c43","targetEntityId":0},{"x":-1260,"id":"e384375498783142","inputCount":2,"group":"","behaviorType":"logic.logic.Storage","outputCount":1,"name":"Save","y":64,"storageKey":null},{"x":-900,"id":"d9e714d90931e148","tag":"Health","startVal":6,"inputCount":3,"group":"","behaviorType":"logic.logic.Value","outputCount":1,"name":"Number","y":448},{"x":-900,"delay":2,"id":"e38608dd233dd448","inputCount":3,"group":"","behaviorType":"logic.triggers.Timer","outputCount":1,"count":1,"name":"Timer","y":544},{"x":-720,"id":"e385a60c49088a4c","inputCount":1,"group":"","behaviorType":"logic.gameflow.NextLevel","outputCount":1,"levelName":"Restart Current","name":"NextLevel","y":480},{"x":-1170,"id":"d9e614a44dfdbb4c","tag":"ouch","startVal":-2,"inputCount":3,"group":"","behaviorType":"logic.logic.Value","outputCount":1,"name":"Number","y":320},{"x":-630,"comp_x":518,"max":6,"inputCount":1,"comp_y":16,"group":"","behaviorType":"logic.hud.Bar","outputCount":1,"name":"Bar","y":256,"barColor":13834521,"frameColor":4611364,"val":6,"id":"d9e90c50fdca644a"}],"v":"2"}} [/spoiler]

Oh, connect the 6 that goes to the bar to the (in) of the other 6. I forgot to do that, and my very very very weak slow awful WiFi hotspot keeps crashing, I have like 0-2 bars, it keeps saying I have limited access or no internet access, and I’m getting tired of resetting it, so hopefully that works for you.

Mhx Ar
great effort!!
it work partly now,( it restart when it hit ), but the problem is that the value of health is not saved, and when I tried to connect the 6 that goes to the bar to the other (in) 6 instead of (set) it crashed all the time!!
Thanks again :slight_smile: and sorry for your WiFi

It crashed for you too? I thought maybe it was just me. I’m not sure what causes the crashing. There has to be a way around it.

Mhx Ar
yes it crash fortunately, hopefully I’ll find a way to do it

Hello