Verse Library verse

01 Device

Links a button press to open and close a door device with a timed delay.

verse-library/verse-events-and-how-devices-talk-to-each-other/01-device.verse

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

# This is our custom device. It holds the button and door.
# Think of it as a box containing both parts.
MySecretDoor := class(creative_device):

    # These are the pieces we will connect in the editor.
    # A 'variable' is a name for a thing that can change.
    @editable
    Button : button_device = button_device{}

    @editable
    Door : door_device = door_device{}

    # This function runs when the game starts.
    # It sets up the "phone line" between button and door.
    OnBegin<override>()<suspends> : void =
        # Subscribe means "listen for this event."
        # When the button is pressed, run the OpenDoor function.
        Button.InteractedWithEvent.Subscribe(OpenDoor)

    # This is the function that actually opens the door.
    # The agent parameter is required by InteractedWithEvent's delegate signature.
    OpenDoor(Agent : agent) : void =
        # This tells the door to open!
        Door.Open()

        # Let's add a little delay so the door doesn't snap instantly.
        # It waits 1 second, then closes.

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