# Can somebody please explain to me what is happening in this code?

**URL:** <https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite\
**Created:** [March 26, 2023, 3:46am UTC](https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701 "2023-03-26T03:46:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TZZonerPlayz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TZZonerPlayz](https://forums.unrealengine.com/u/TZZonerPlayz)\
**Post date:** [March 26, 2023, 3:46am UTC](https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701/1 "2023-03-26T03:46:14Z")

</div>

Hello there,

I need help explaining how does this code work.

Here is the code: (Credit for the Fortnite Verse documentations for this code):

```auto
if (PotionType = "damage"):
            if ((PlayerHealth > PotionDamageAmount)):
                set PlayerHealth = PlayerHealth - PotionDamageAmount
                Print("Full damage")
            else if (PlayerHealth > MinHealth):
                # Give player one more chance if their health is low
                set PlayerHealth = 1.0
                Print("PlayerHealth set to 1.0")
            else:
                set PlayerHealth = 0.0
                Print("Player eliminated!")

```

The reason why I need someone to explain this code for me is because there is one part of the code that I don’t understand and that part is this:

```auto
else if (PlayerHealth > MinHealth):
                # Give player one more chance if their health is low
                set PlayerHealth = 1.0
                Print("PlayerHealth set to 1.0")

```

That is the part that I’m confused about because from my understanding, it says right here that if PlayerHealth is bigger than MinHealth then, it would set the PlayerHealth to MinHealth and it would print PlayerHealth set to 1.0 and that’s the part that I don’t understand so can somebody please explain this code for me? Thank you.

---

<div class="post-metadata">

**Author:** ![Yolziii](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yolziii/32/638353_2.png) [@Yolziii](https://forums.unrealengine.com/u/Yolziii)\
**Post date:** [March 26, 2023, 6:07am UTC](https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701/2 "2023-03-26T06:07:24Z")

</div>

Yeah, it seems like you’ve understood everything correctly. This is the logic of this particular poison mechanic.

---

<div class="post-metadata">

**Author:** ![CaveBoy\_88](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CaveBoy\_88](https://forums.unrealengine.com/u/CaveBoy_88)\
**Post date:** [March 27, 2023, 4:58pm UTC](https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701/3 "2023-03-27T16:58:56Z")

</div>

@TZZonerPlayz if you’re still having issues understanding what the code is doing, it might help to assign values to `PlayerHealth` and `PotionDamageAmount` in your mind and then work through the control flow.

Imagine `PlayerHealth` is 24.0 and `PotionDamageAmount` is 25.0. This scenario should help you figure out the logic 🙂

---

<div class="post-metadata">

**Author:** ![Clebito](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clebito/32/634989_2.png) [@Clebito](https://forums.unrealengine.com/u/Clebito)\
**Post date:** [March 27, 2023, 5:16pm UTC](https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701/4 "2023-03-27T17:16:46Z")

</div>

The code is used when the player is using a Damage Potion. So, the first step is checking if the Player Health is greater than the damage amount (so it doesn’t kill the player). If it is, it applies the full damage and the code is done.  
The “else if” only applies if the player health is equal or lower the Damage Amount (only happens if the first part “failed”) and if it is greater than the MinHealth(1.0), so in order to not kill the player instantly, it sets his Health to 1.0. That’s why it sets his life to 1.0: His life was not big enought to receive the full damage, so instead of killing the player, it sets his Health to 1.0 to give him one more chance  
Lastly, if the player’s health is not greater than the Damage Amount and not greater than the MinHealth (in other words, if his Health = 1.0), it will kill him

---

<div class="post-metadata">

**Author:** ![TZZonerPlayz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TZZonerPlayz](https://forums.unrealengine.com/u/TZZonerPlayz)\
**Post date:** [March 27, 2023, 10:44pm UTC](https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701/5 "2023-03-27T22:44:45Z")

</div>

If that’s the case then, why does it say in the else if if the PlayerHealth is greater than MinHealth?

---

<div class="post-metadata">

**Author:** ![Clebito](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clebito/32/634989_2.png) [@Clebito](https://forums.unrealengine.com/u/Clebito)\
**Post date:** [March 27, 2023, 10:57pm UTC](https://forums.unrealengine.com/t/can-somebody-please-explain-to-me-what-is-happening-in-this-code/823701/6 "2023-03-27T22:57:02Z")

</div>

The function considers 3 different scenarios when the player takes damage:

1. If the player’s health is greater than the damage amount, it will cause full damage (Example: player health is 80 and damage taken is 70. This will leave them with 10hp and the function will be complete).

2. The second scenario only happens if the player’s health is not greater than the damage amount but is greater than MinHealth (which is 1, if I remember correctly). Taking the damage will set the player’s health to 1hp. (Example: player health is 50 and damage taken is 70. This would normally eliminate them, but in this case, it will set PlayerHealth to 1.0 to give them one last chance and avoid being eliminated too quickly).

3. The last scenario will only happen if the player’s health is not greater than the damage amount and also not greater than MinHealth, which means they probably have 1HP. In this case, the damage will eliminate them.
