Verse Library verse

01 Standalone

Connects editor placed button devices to an item granter via event subscription.

verse-library/getting-started-with-devices-in-fortnite/01-standalone.verse

# This script connects buttons to actions.
# Think of this as the brain of your island.

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

# We create a "Class" which is like a blueprint for our logic.
# It’s like a custom game mode.
ChaosLogic := class(VerseSimContext):
    # This is the "Constructor". It runs once when the game starts.
    # It’s like the Battle Bus taking off—you set up the rules before anyone jumps.
    OnBegin<override>()<static>:
        # 1. Find our devices by name.
        # We are looking for the buttons and the item granter we placed in the editor.
        reward_button := FindDevice[Button](`Reward_Button`)
        punishment_button := FindDevice[Button](`Punishment_Button`)
        loot_granter := FindDevice[ItemGranter](`Loot_Grant`)
        
        # 2. Connect the Reward Button.
        # When this button is pressed...
        reward_button.PressedEvent.Subscribe(
            # ...do this function:
            func():
                # Grant the player a Pump Shotgun.
                # We use the "Grant" function on the Item Granter.
                # We assume the granter is set up to give a shotgun in its options.
                loot_granter.Grant()
                
                # Optional: Print a message to the console for debugging.
                Print("You got the shotgun!")

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