Verse Library verse

03 Fragment

Defines a reusable device class that calculates and dispenses loot based on player health states.

verse-library/basics-of-writing-code-8-how-input-parameters-and-arguments-work-in-verse/03-fragment.verse

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

class LootDevice extends Device {
    
    # This is the function we defined earlier
    GetLootForHealth(current_health : float) : string = |
        if (current_health < 50.0): |
            return "Shield_Potion"
        else if (current_health <= 80.0): |
            return "Bandage"
        else: |
            return "Assault_Rifle"

    OnBegin<Over>() override: |
        # When the device starts, it waits for a player interaction
        # For this demo, let's just log the loot for a hypothetical player
        # In a real build, you'd pass Player.GetHealth() as the argument
        
        # Example: Player has 30 health
        player_health : float = 30.0
        loot : string = GetLootForHealth(player_health)
        
        # Output the result to the console
        Print(GetLocalizedString("Loot_Dispensed", loot))
}

Comments

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