Verse Library verse

10 Countdown Before Heartbeat

Manages heartbeat warning countdowns and updates the player UI text dynamically.

extracted-snippets/documentation/en-us/uefn/verse-prop-hunt-template-3-playing-effects-on-idle-players-in-unreal-editor-for-fortnite/10-countdown-before-heartbeat.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/verse-prop-hunt-template-3-playing-effects-on-idle-players-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/uefn/verse-prop-hunt-template-3-playing-effects-on-idle-players-in-unreal-editor-for-fortnite.md
# Section:    Countdown Before Heartbeat
 # Delays until HeartBeatWarningTime should start. Then counts down by HeartBeatWarningTime and sets the countdown text. Clears the text when deferred.
 CountdownTimer(PropAgent:agent)<suspends>:void=
     Logger.Print("Starting heart beat countdown.")
     if (UIData := HeartBeat.WarningUI[PropAgent]):
         Sleep(HeartBeat.MoveTime - HeartBeat.WarningTime) # Sleep for the amount of time before the warning appears.
         Logger.Print("Starting heart beat warning.")
         var WarningTimeRemaining:int = 0
         if (set WarningTimeRemaining = Ceil[HeartBeat.WarningTime]) {}
             # A defer happens when the function completes or if it is canceled, such as if it loses a race.
             # So in this case, the warning text is cleared when the countdown finishes or if the prop agent moves before the countdown finishes.
             defer:
                 UIData.Text.SetText(HeartBeatWarningClear)
             # Set the warning text to the time remaining, wait a second, and then decrement the time remaining. If the countdown completes, break the loop.
             loop:
                 Logger.Print("Heart beat in {WarningTimeRemaining} seconds.")
                 UIData.Text.SetText(HeartBeatWarningMessage(WarningTimeRemaining))
                 Sleep(1.0)
                 set WarningTimeRemaining -= 1
                 if (WarningTimeRemaining <= 0):
                     break
     else:
         Logger.Print("UIData not found.")
Copy full snippet

Comments

    Sign in to vote, comment, or suggest an edit. Sign in