Verse Library verse

01 Device

Subscribes to button clicks to increment a score variable and update a custom HUD display.

verse-library/hud-controller/01-device.verse

# This is our main script.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

# This is our Scoreboard script.
Scoreboard := class(creative_device):
    # This is the button we dragged into the island.
    # We connect it in the editor.
    @editable
    ClickButton: button_device = button_device{}

    # This is the HUD Controller.
    # It is the tool that talks to the screen.
    # @editable means we can see it in the editor.
    @editable
    MyHUD: hud_controller_device = hud_controller_device{}

    # This is our variable.
    # It is a box for our score.
    # It starts at zero.
    # var means we can change it later.
    var CurrentScore: int = 0

    # This function runs when the game starts.
    OnBegin<override>()<suspends>: void =
        # We connect our button to a function.
        # When the button is clicked, run this code.
        # Note: button_device.InteractedWithEvent passes the agent who clicked.
        ClickButton.InteractedWithEvent.Subscribe(OnButtonClicked)

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