How do I Deplete Health When Hunger Reaches 0?

Hello,

I made a hunger system a few days ago and wanted to add health depletion when the hunger reaches 0. I have been playing around for the past couple hours but I can’t figure it out.
Can somebody help me with this? It’s a very basic hunger system so only one screenshot is provided.

Thanks,

Hello, I would recommend that when you set hunger, you use a branch to check if hunger is <= 0. If true, set a timer for an event that subtracts from the health. If false, clear/stop that same health depletion timer, and move on to create the health bar widget.

And, if I would add a suggestion, it is not the best idea to spawn a new widget every time the health is updated, but rather to update the widget, by doing whatever it does to update itself (Event Construct?).

Hi Jamendxman3,

I tried what you said and it didn’t work. I’m probably doing it wrong but, here is my code:

On event begin plan, start a looping timer that calls a function every 3 seconds.
In that function, check if hunger <= 0, and if so, subract one health.
Change “3” and “one” to whatever values fit your game.

That is pretty basic case (1 minute of blueprint scripting)… I recommend you to do some tutorials first, because when it comes to harder stuff, then it will be pain for you and also if you want to do games seriously, you need to take some time and learn basics first…
I recommend you to do this tutorial: http://shootertutorial.com/
It took me to 1-2 months (or better said 200-300 hours) to complete this but it learned me really much about blueprint scripting and communication between blueprints…

First of all, I’d encourage you to try and structure your blueprints nicer. A nice structure is key to not getting lost in your own blueprints as they’ll eventually turn into a cobweb of sorts. Using comments and tooltips are always highly encouraged - not only for your own sake, but also any people that might be working with you.

Secondly, the reason that it’s not working is because you misunderstood the concept of getting and settings variables. Look at the screenshot you posted previously*(do also note that you forgot to hook up the execution pins(the white ones))*.

If you want to decrease the value of the float variable, you’ll want to do it like this;

The pin at the end of the SET will return the new value of the variable. Lets assume the default value is 100.0 and we decrease it by 10.0 like above - the second pin would return 90.0, not 100.0.

As for updating the widget, there’s plenty of tutorials and information available on how to do this. You just gotta type the magic words into Google :wink: