Verse Library verse

01 Device

Connects a single trigger device to multiple audio, lighting, and movement devices using event subscriptions.

verse-library/bind-device-functions-and-events/01-device.verse

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

# This is our main script. Think of it as the "Game Director"
# controlling all the devices.
chaos_button_system := class(creative_device):
    # We define variables for our devices.
    # These are like your "inventory slots" for devices.
    TriggerDevice: trigger_device = trigger_device{}
    SpeakerDevice: audio_player_device = audio_player_device{}
    LightDevice: customizable_light_device = customizable_light_device{}
    MoverDevice: prop_mover_device = prop_mover_device{}

    # The 'On Begin' function runs when the island starts.
    # This is where we do all our "introductions" (binding).
    OnBegin<override>()<suspends>: void =
        # BINDING 1: The Trigger -> The Speaker
        # When the trigger is activated, call the Speaker's "Play" function.
        TriggerDevice.TriggeredEvent.Subscribe(OnTriggered)

        # Note: In real UEFN, you can also do this visually in the device UI,
        # but seeing it in code makes the "Event -> Function" link crystal clear.

    OnTriggered(Agent: ?agent): void =
        # BINDING 2: The Trigger -> The Light
        # When the trigger is activated, call the Light's "Set Active" function.
        # We pass 'true' to turn it ON.
        LightDevice.TurnOn()

        # BINDING 3: The Trigger -> The Prop Mover

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