Verse Library verse

04 Awaiting A Creative Device Event

Uses race expressions to ensure players can only select one button out of multiple choices.

extracted-snippets/documentation/en-us/uefn/coding-device-interactions-in-verse/04-awaiting-a-creative-device-event.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/coding-device-interactions-in-verse
# Local doc:  epic-docs/documentation/en-us/uefn/coding-device-interactions-in-verse.md
# Section:    Awaiting a Creative Device Event
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

make_a_choice_device:= class(creative_device):

    @editable
    MakeChoice:trigger_device = trigger_device{}

    @editable
    RedButton:button_device = button_device{}

    @editable
    BlueButton:button_device = button_device{}

    OnBegin<override>()<suspends>:void=
        # This waits for the player to step on the trigger and prevents any other code from executing here until this happens.
        # This means that if the player interacts with the two button devices, nothing will happen until this event occurs.
        MakeChoice.TriggeredEvent.Await()
        Print("Make a choice: red button and stay in wonderland, or blue button and wake up back in your bed.")

        # Both block expressions execute at the same time in this race expression.
        # When the player interacts with one of the buttons, waiting for the other button interaction will cancel.
        # This means that the player can only interact with one of the Button devices.
        race:
            block:
                RedButton.InteractedWithEvent.Await()
                Print("You chose to stay in wonderland.")

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