Verse Library verse

01 Device

Toggles a custom text widget on or off for each player via a button press.

verse-library/creating-and-removing-widgets/01-device.verse

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

# This is our main device class. It inherits from creative_device
# so it can live in the level and react to game events.
toggle_message_board := class(creative_device):

    # Wire your Button device to this property in the
    # Verse Explorer (Details panel) after uploading.
    @editable
    ButtonDevice : button_device = button_device{}

    # We create an empty map to store widgets.
    # The key is the player. The value is the widget.
    var WidgetMap : [player]text_block = map{}

    # OnBegin runs automatically when the game session starts.
    OnBegin<override>()<suspends> : void =
        # Connect the button's InteractedWithEvent to our handler.
        ButtonDevice.InteractedWithEvent.Subscribe(OnButtonPressed)

    # This function runs every time the button is pressed.
    OnButtonPressed(Agent : agent) : void =
        # We need a player, not just an agent. Convert safely.
        if (Player := player[Agent]):
            # Get the player_ui interface so we can add/remove widgets.
            if (PlayerUI := GetPlayerUI[Player]):

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