Verse Library verse

01 Device

Manages player health and shield values, clamping negatives to zero for UI display.

verse-library/making-custom-health-and-shield-bars/01-device.verse

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }
using { /UnrealEngine.com/Temporary/Diagnostics }

# This is our main script class.
# It holds all our health logic.
health_manager := class(creative_device):

    # This is a variable for health.
    # It starts at 100.
    # Think of it as a box holding the number 100.
    var CurrentHealth : float = 100.0

    # This is a variable for shields.
    # It starts at 50.
    var CurrentShield : float = 50.0

    # This function updates the health bar.
    # It takes the new health value as input.
    UpdateHealthBar(NewHealth : float) : void =
        # Check if the new health is valid.
        # Health cannot be negative.
        if (NewHealth < 0.0):
            set CurrentHealth = 0.0
        else:
            set CurrentHealth = NewHealth

        # Print a message to see it working.
        Print("Health is now: {CurrentHealth}")

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

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