Verse Library verse

01 Device

Subscribes to trigger events to detect player contact, validates agent types, and activates game logic.

verse-library/building-lego-islands-in-fortnite/01-device.verse

# This is a simple script for a LEGO brick
# It makes the brick glow when a player touches it

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

# We create a "Device" called GlowingBrick
# This is like a special LEGO piece with magic
GlowingBrick := class(creative_device):

    # TriggerDevice is placed in the editor and linked here.
    # It detects when a player enters the brick's area.
    @editable
    Trigger : trigger_device = trigger_device{}

    # This runs when the game starts
    OnBegin<override>()<suspends> : void =
        # We wait for a player to activate the trigger
        # This is called an "Event"
        Trigger.TriggeredEvent.Subscribe(OnBrickTouched)

    # This function runs when the trigger fires
    # Agent is the player who stepped on the trigger
    OnBrickTouched(Agent : ?agent) : void =
        # Turn the agent into a fort_character so we can use character actions
        if (A := Agent?, Character := A.GetFortCharacter[]):
            # Print a message to the output log to confirm the glow fired
            # note: Verse has no runtime SetMaterialColor API for creative_devices;

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