Why doesn't this work?

HurtPlayer() : void=
        Playspace : fort_playspace = GetPlayspace() 
        AllPlayers : []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                FortniteCharacter.Damage(CalculateDamage())

    HealPlayer() : void=
        Playspace : fort_playspace = GetPlayspace() 
        AllPlayers : []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                FortniteCharacter.Heal(35.0)
    
    CalculateDamage() : float=
        var PlayerHealth : float = 100.0
        PotionDamageAmount : float = 80.0
        MinHealth : float = 1.0
        if (PlayerHealth > PotionDamageAmount):
            return PotionDamageAmount
        else if (PlayerHealth > MinHealth):
            return PlayerHealth - MinHealth
        else:
            return PlayerHealth
        
        
        

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        HurtPlayer()
        Print("Player is damaged")
        Sleep(3.0)
        HealPlayer()
        Print("Player has been healed!")
        Sleep(3.0)
        HurtPlayer()

This is from lesson 7 in the docs, and it just does not work and I can’t figure out why.
HALP.
I should add I expect this to leave the player’s health at 1.0

Put in some Print strings and check the value of Player Health in the Calculate Damage function. The first time through it works. Health drops by 80 and goes up by 35. The second time Calculate Damage is called, the Player’s Health re-sets to 100 in the function, so PotionDamage goes through again and drops value to 0 and kills the character. Are you following a section of code already written or is this code you modified yourself? Every time you call CalculateDamage, you are re-initializing Player Health to 100 in the function, but not in the game. You should consider using the GetHealth value from the character.

CalculateDamage() : float=
var PlayerHealth : float = 100.0
PotionDamageAmount : float = 80.0
MinHealth : float = 1.0
if (PlayerHealth > PotionDamageAmount):
Print(“This is first IF {PlayerHealth}”)
return PotionDamageAmount
else if (PlayerHealth > MinHealth):
Print(“This is ELSE IF {PlayerHealth}”)
return PlayerHealth - MinHealth

using { /Fortnite.com/Characters}
using { /Fortnite.com/Devices }
using { /Fortnite.com/Playspaces}
using { /Fortnite.com/UI}
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath}
using { /UnrealEngine.com/Temporary/UI}
using { /Verse.org/Colors}
using { /Verse.org/Colors/NamedColors}
using { /Verse.org/Random}
using { /Verse.org/Simulation }

hello_world_device := class(creative_device):

#place in level to inflict damage
@editable
MyTrigger1 : trigger_device=trigger_device{}

#place in level to restore health
@editable
MyTrigger2 : trigger_device=trigger_device{}

var PlayerHealth :float = 100.00
    

# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
    
    MyTrigger1.TriggeredEvent.Subscribe(HurtPlayer)
    
    MyTrigger2.TriggeredEvent.Subscribe(HealPlayer)
    

HurtPlayer(Agent:?agent) : void=
        Playspace : fort_playspace = GetPlayspace() 
        AllPlayers : []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                FortniteCharacter.Damage(10.0)
   
                

HealPlayer(Agent: ?agent) : void=
        Playspace : fort_playspace = GetPlayspace() 
        AllPlayers : []player = Playspace.GetPlayers()
        if (FirstPlayer : player = AllPlayers[0]):
            if (FortniteCharacter : fort_character = FirstPlayer.GetFortCharacter[]):
                FortniteCharacter.Heal(5.0)
    

#Not sure what you want to do with this function. 
CalculateDamage() : float=
        
        PotionDamageAmount : float = 80.0
        MinHealth : float = 1.0
                       
        if (PlayerHealth > PotionDamageAmount):
            set PlayerHealth=PlayerHealth - PotionDamageAmount
            return PotionDamageAmount
        else if (PlayerHealth > MinHealth):
            return PlayerHealth - MinHealth
        else:
            return PlayerHealth

#rewrote in a way that made more sense to me so you can better assess in game level

Thanks both of you. They way the lesson has it is that CalculateDamage() is what determines how much the player is damaged when HurtPlayer() is called. That’s fine and it works but in my code I call HurtPlayer() another time because I wanted to test the other use case where if the Player’s health is already lower than the incoming damage, it should set Player health to 1 to “give player another chance” before death.