# How to quit this if-mess?

**URL:** <https://forums.unrealengine.com/t/how-to-quit-this-if-mess/1425393>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, Code, question, fortnite\
**Created:** [November 27, 2023, 11:02am UTC](https://forums.unrealengine.com/t/how-to-quit-this-if-mess/1425393 "2023-11-27T11:02:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nyarla91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nyarla91](https://forums.unrealengine.com/u/nyarla91)\
**Post date:** [November 27, 2023, 11:02am UTC](https://forums.unrealengine.com/t/how-to-quit-this-if-mess/1425393/1 "2023-11-27T11:02:59Z")

</div>

```auto
HandleDamage(DamageResult : damage_result):void=
        if (TargetCharacter := fort_character[DamageResult.Target]):
            if (Instigator := DamageResult.Instigator?):
                if (InstigatorAgent := Instigator.GetInstigatorAgent[]):
                    if (InstigatorCharacter := fort_character[InstigatorAgent]):
                        if (TargetCharacter <> InstigatorCharacter):
                            if (ScoreTotal := Round[DamageResult.Amount * ScorePerPointOfDamage]):
                                ScoreManager.SetScoreAward(ScoreTotal)
                                ScoreManager.Activate(InstigatorAgent)

```

Is there any way to handle this? It seems like due to the requirement of the Verse to be sure no expression fails I have to do this infinite nesting? Is it possible to make it look more like this (it’s C# code):

```auto
private void HandleDamage(DamageResult damageResult)
    {
        FortCharacter targetCharacter = damageResult.Target;
        if (damageResult.Instigator == null)
            return;
        Agent instigatorAgent = damageResult.Instigator.GetInstigatorAgent();
        FortCharacter instigatorCharacter = instigator.GetFortCharacter();
        if (targetCharacter == instigatorCharacter)
            return;
        int scoreTotal = (int) Math.Round(damageResult.Amount * _scorePerPointOfDamage);
        _scoreManager.SetScoreAward(scoreTotal);
        _scoreManager.Activate(instigatorAgent);
    }

```

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [November 27, 2023, 11:23am UTC](https://forums.unrealengine.com/t/how-to-quit-this-if-mess/1425393/2 "2023-11-27T11:23:31Z")

</div>

Is this what you had in mind?

```auto
HandleDamage(DamageResult : damage_result): void =

    if:
        TargetCharacter := fort_character[DamageResult.Target]
        InstigatorAgent := DamageResult.Instigator?.GetInstigatorAgent[]
        InstigatorCharacter := InstigatorAgent.GetFortCharacter[]
        TargetCharacter <> InstigatorCharacter
        ScoreTotal := Round[DamageResult.Amount * ScorePerPointOfDamage]
    then:
        ScoreManager.SetScoreAward(ScoreTotal)
        ScoreManager.Activate(InstigatorAgent)

```

You can also return from the function in the same way as your other example.

```auto
HandleDamage(DamageResult : damage_result): void =

    if. not DamageResult.Instigator?.GetInstigatorAgent[] then. return

```

---

<div class="post-metadata">

**Author:** ![nyarla91](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nyarla91](https://forums.unrealengine.com/u/nyarla91)\
**Post date:** [November 27, 2023, 11:53am UTC](https://forums.unrealengine.com/t/how-to-quit-this-if-mess/1425393/3 "2023-11-27T11:53:57Z")

</div>

Didn’t know about the first option, thank you!

About return. Doesn’t this line mean that TargetCharacter variable will only be available in "if "scope and not in method/function afterwards?

```auto
if (not (TargetCharacter := fort_character[Result.Target])): return

```

---

<div class="post-metadata">

**Author:** ![ManualPotato](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/manualpotato/32/1144902_2.png) [@ManualPotato](https://forums.unrealengine.com/u/ManualPotato)\
**Post date:** [November 27, 2023, 3:27pm UTC](https://forums.unrealengine.com/t/how-to-quit-this-if-mess/1425393/4 "2023-11-27T15:27:25Z")

</div>

No worries. It does, yea. I believe the first option is needed if you want to use the variable.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [December 27, 2023, 3:28pm UTC](https://forums.unrealengine.com/t/how-to-quit-this-if-mess/1425393/5 "2023-12-27T15:28:07Z")

</div>

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