Ignore Array Index on Condition

Trying to create a simple Enemy encounter where the Enemy checks if it has more stats than you, it chooses to attack that stat. This BP checks four different X-Y and creates MakeArray from their results, to get the Index with Max value. I want to ignore an index when a Y’s value is equal to 0. So that the linked Enum won’t be selected when Y is equal to 0. Can’t figure out how to do it. Or should I approach this differently?

TL;DR

How can I ignore an Array Index when an item that’s creating the Array has met the condition?

Edit: Fixed wording error.

If I understand correctly, you only want to select a body part to attack if the value difference is positive (Enemy stat stricly greater than player stat).

You can try something along those lines:

Obviously I don’t have access to your exact nodes, but you get the logic behind this example.
You can have a branch node (if statement) to check the max value of the array and only set your body part if it is positive.

Ty for the response! I don’t want Enemy to attack Player only if the difference is Positive, because it’s a chance-based attack so the Enemy could decide to attack even when all the results are negative. It will choose the max value from those Negative indexes. If they are -2, -2 ,-2, -1, it will choose the -1 one. But it shouldn’t attack a Body part when its related attribute hits 0, because their values don’t go negative. That is why Enemy should ignore a body part when its related attribute is 0.

So if one of the Attributes hit 0, an index from the Array should be ignored.

Edit: I think I worded incorrectly in my initial post. Apologies.

Ok I think I know what you mean. Correct me if I’m wrong.

You have body parts related to attributes like so:

  • Head = Int
  • Body = Cha
  • Arms = Str
  • Legs = Dex

Your enemy choses to attack a body part based on the stat differences between it and the player.

You only want the enemy to attack a body part if its stat is above 0, if not, you chose the next best one.

In that case, the logic is a little bit trickier, but not so hard. In order to not blow up the size of your graph, create a new function like this:

Now you simply have to replace how you create your array like so:


(I’m sorry the wiring is a mess)

This way, unless all your stats are 0, the enemy will prioritize its biggest advantage, ignoring stats equal to 0.

In the case that they are all 0, if it is even possible in your game, you would have to implement some more logic.

1 Like

I must say your clear understanding of my messed up core mechanics amazes me because you got it completely correct :smiley:

And I think what you come up with will work just fine because In the case that they are all 0, I’ll give the turn to the Player again just for now.

But in the actual game, this scenario will probably end in Player loss. It’s hard to come back from there. But even if you are alive there it means Enemy will go defensive mode, executing other mechanics.

Thank you for all your help. I’ll be implementing this right now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.