Verse Library verse

01 Device

Increments a mutable score variable whenever a player collects a designated collectible object.

verse-library/using-collectible-object-devices-in-fortnite-creative/01-device.verse

# LootGoblin.verse
# This script makes a collectible object give rewards and update a score.

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

# This is our main device. Think of it as the brain attached to the Collectible Object.
# creative_device is the correct base class for UEFN island scripting.
LootGoblin := class(creative_device):

    # A reference to the Collectible Object device placed in the editor.
    # Drag your Collectible Object device into this slot in the Verse panel.
    @editable
    CollectibleDevice : collectible_object_device = collectible_object_device{}

    # 1. The Variable: A container for the player's score.
    # We start at 0. This is like an empty XP bar.
    # 'var' marks this as mutable so we can change it later.
    var PlayerScore : int = 0

    # 2. The Setup: What happens when the game starts?
    OnBegin<override>()<suspends> : void =
        # Subscribe our handler to the collectible's CollectedEvent.
        # Every time a player picks up the collectible, OnPickup will run.
        CollectibleDevice.CollectedEvent.Subscribe(OnPickup)
        Print("Loot Goblin is awake. Go get those gems!")

    # 3. The Event Handler: called automatically when CollectedEvent fires.
    # CollectedEvent passes the agent (player) who triggered the pickup.

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