Change property when health variable exceeds a specific number

Screen Shot 2014-04-10 at 5.56.40 PM.jpg

Hello, I’m trying to run some test in my scene and make it so that one my health variable reaches 25 or above, the color of a specific light in my scene changes from red to green. I thought what I had made sense but, I guess it doesn’t because nothing it happening. Would anyone mind looking at my blueprints above and point me where I’ve most likely gone wrong. Very new to the scripting side of things. Thanks in advance!

you always need a red node as starting point of your event execution, and always hookup white lines that represnts actual execution flow.

I can barely read the nodes in that picture, but yes you need something to execute them.

Additionally, I would attach an In Range(Float to your branch boolean and put the range you want things to happen at. For instance, if in range 75-100 then branch says true and it executes a green light. If that is false, then maybe it executes another branch that says if 50-75 then yellow, and it’s false would lead to a red light for anything under 50(or whatever is left after the first 2 range checks).

Hopefully, this external image post will show up larger, not sure what happened before. I took your advice Zeustiak and tried out the ‘For instance’ Node, which makes sense. Penguin, was of course right in me forgetting to hook up an event to drive the entire sequence.

Let me back up and try to describe what I’m trying to do in as few a words as possible. I’ve mashed together much of the blueprints from the MouseDriven Experience and the HUD setup with the health pickup from the Content Examples pack. I have a character in the center of my scene that I click on to fire off animation, sound and using health points to drive up a meter from 0 to 100. In the blueprint above, I thought I’d try hooking up the branch condition after my initial mouse-click sequence, and have it say if the Health Value was a minimum of 25 - 50 that it would do something such as set the light color to green for the sake of testing.

I’m just not really sure where an operation such as this should exist and how often it should be looking to see where the score is at. Should it be every time the user clicks the character or is that too much? Hopefully I haven’t made things more confusing.

Also, it’s worth noting that most of the blue prints exist in the Level Blueprint as I’m planning on this being a fairly small game.

For example, your GetPlayerHealth(blue) will never run because no white line goes into the execution connection(one that looks like a baseball home base turn 90 degree counterclockwise.).
Same with your bottom SetLightColor on the top right of your graph.
Any blueprint execution starts from a red node, there is no exception.

So I did turn off the blue light portion to keep things simple, I should have removed that before the screenshot. The light is red by default. Again, I completely get what you are saying about the “GetPlayerHealth”. Here is what is tripping me up. “Get Player Health” is defined in A Blueprint listing a few events used mainly by the HUD in the game. It of course is an float. Player Health is further defined on my Pawn Player Class,

If I could just access that “Health” node that should carry the same number I’m looking for, I wouldn’t have the issue above of nothing driving “Get Player Health” I really just want to check the current Health Count number against the numbers in the “In Range” node to trigger the rest of the chain. Again, I’ve probably messed all of this up. But should I just attach this to event begin play where I can?

Ok, last one :D. I did a little more digging and tried the same logic with a clean scene and setup the score in a much more simple fashion. I figured that I should be able to hit the “G” key 25 times and a light in my scene would turn on, but nothing happened. Feeling a bit stumped, and it’s late.

It’s because you assume “Event Begin Play” continue to run after game starts.
Remember, all the red node only fire depends on the condition it listed, Event Begin Play will only fire once when you load the level, and won’t run again.
If you change Event Begin Play to Event Tick, which will run your branch check every frame.

And if later on you know how to do custom events, you can only fire a custom event when setting your pawn’s health, and then check if the value is larger than say 50, if so, fire a custom events.
Thus you will only fire one event when the condition changed, not check health/score every frame.

If you want to know when a variable changes you either need to:

  • Poll that variable every frame using a Tick event. This is easy but not very efficient.
  • Rather than writing to the variable directly, make a ‘Set Health’ function which modifies the health variable and then checks to see if it meets some criteria.