Verse Library verse

02 Fragment

Links a button device to a trap, enabling it when a player interacts with the button.

verse-library/verse-functions-and-when-to-use-them-in-a-fortnite-island/02-fragment.verse

# A Verse Device that fires a trap when a button is pressed.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

device ButtonTrapController : creative_device {

    # This is the trap we want to control.
    # The @editable tag lets us assign it in the UEFN Details Panel.
    @editable
    Trap : trap_device = trap_device{}

    # This is the button we want to watch.
    # The @editable tag lets us assign it in the UEFN Details Panel.
    @editable
    Button : button_device = button_device{}

    # OnBegin runs automatically when the game session starts.
    # We use it to subscribe to the button's InteractedWithEvent.
    OnBegin<override>()<suspends> : void = {
        # Tell the Button: when someone interacts with you,
        # call our FireTheTrap function.
        Button.InteractedWithEvent.Subscribe(FireTheTrap)
    }

    # Here is the function that does the work.
    # It receives the agent (player) who pressed the button.
    FireTheTrap(Presser : agent) : void = {
        # Tell the trap to enable so it can fire!
        Trap.Enable()

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