using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /Verse.org/Native } # This is our main device. It holds the code. health_bar_device := class(creative_device): # This is a variable. It holds the current health. # It starts at 100. var current_health: float = 100.0 # This is a variable to track the health percentage for the UI. # We will update this to drive the visual bar. var health_percentage: float = 1.0 # This function runs when the game starts. OnBegin(): void = # First, we set the initial health. # We send 1.0 to the UI. 1.0 means 100% full. set health_percentage = 1.0 Print("Health bar is ready! Press Space to take damage.") # This function reduces health when called. TakeDamage(): void = # Let's take some damage. set current_health = current_health - 25.0 # Check if health is below zero. if (current_health < 0.0): set current_health = 0.0 # Calculate the percentage (0.0 to 1.0). # If health is 50, percentage is 0.5. set health_percentage = current_health / 100.0 # Send the new percentage to the UI. # The health_percentage variable now holds the updated value. Print("Health is now: {current_health}")