Help with functions

Hello, I have two functions (Heal and Damage). If CurrentHealth variable is Less or Equal 6, the character’s walk speed slows down, if the variable is Greater 6, the character’s walk speed restores its original value. It works when I want to slow down my character but it doesnt in the opposite direction. How can I make all inside a single function?

Hey @EricTompson! Welcome to the forums!

So I think the important thing to note here is what causes this script to go. What starts it? We need to take a look at the opposite end. For instance, is this being called on heal? Or only when the character takes damage?

1 Like

Sure, here is my Damage


function

How it restore health? By time, don’t undestand what you mean in the opposite direction, what you show is only on damage function.

Another way to handle it is controlling the Health value (normally in PlayerState), for example in a PlayerController or Pawn BP, so inside in the Tick Event you keep watching the value when changes the Value health can launch the function for update the speed. Another via to controll it is if you have a HUD widget showing the Health Value, you can bind it, if its value changes then fire the desired function to update the Player Speed

Hey again @EricTompson!

So what you’ve got for damage works fine! The issue is when it goes back up, so maybe let’s take a look at the other two functions you have here: “Check Speed” and “Heal”. :slight_smile:

Check Speed is empty, I just forgot to delete it. This is what my Heal function looks like. If I use the nodes that I’ve highlighted in red, everything works fine, but I don’t like the way I’ve made it. As I mentioned in my topic, I want this to be called inside the ‘Damage’ function.

Okay, so if you want all of it to be in one function, use a bool on the function itself labeled “Heal?” and if it is checked, use a different path.

Off of false would be your damage (The version with -), and off of true would be your heal (the version with +).

Make sure when it is used the correct bool is passed through. Then merge the two Execution lines (the white one) at your print string :slight_smile: