Build Your Own: The "Chaos Button" Island
Tutorial beginner compiles

Build Your Own: The "Chaos Button" Island

Updated beginner Code verified

Build Your Own: The "Chaos Button" Island

So you've played Fortnite. You know the drill: looting, shooting, storm circles, and that one moment when you accidentally press a button and the whole island explodes. Now, it's time to be the one holding the detonator.

In this tutorial, we're going to build a "Chaos Button" Island. It's simple, it's satisfying, and it's the perfect way to learn how Verse talks to the game world. We aren't just making a button that says "Do Nothing." We're making a button that triggers a sequence of events—like spawning loot, changing the sky, or maybe just dropping a giant anvil on your friends' heads.

What You'll Learn

  • The Scene Graph: How Fortnite stores every object (props, devices, players) in a massive digital tree.
  • Variables: How to store a number (like a score) that changes while the game is running.
  • Events: How to listen for player actions (like clicking a button) to trigger code.
  • Functions: How to group a bunch of actions into one reusable command.

How It Works

Before we write a single line of code, we need to understand the "brain" of your island. In programming, we call this the Scene Graph.

The Scene Graph: The Ultimate Loot Table

Imagine the Fortnite lobby. There are players, weapons, buildings, and NPCs. In Verse, everything is an Entity. Think of an Entity as a single item in your inventory or a prop on the map.

These Entities are organized in a hierarchy, like folders on your computer.

  • The Root is the island itself.
  • Under the Root, you have folders for "Players," "Props," and "Devices."
  • Inside "Devices," you have your specific button, your score counter, and your storm device.

When you write Verse code, you are essentially reaching into these folders to grab specific items and tell them what to do.

Variables: The Health Bar of Your Logic

In Fortnite, your Health Bar changes as you take damage. It's a value that isn't fixed. In programming, we call this a Variable.

  • Variable: A container that holds a value which can change.
    • Game Analogy: Your Shield Health. It starts at 0, goes up to 100, drops when you get shot, and resets when you respawn.
  • Constant: A value that is set once and never changes.
    • Game Analogy: The max shield cap (100). You can't change the rules of the game to make shields go up to 200 without special settings.

Events: The Storm Timer

You don't want your code to run constantly in the background like a fan. You want it to run when something happens. This is an Event.

  • Event: A signal that says, "Hey, something just happened!"
    • Game Analogy: The Storm closing. The game checks every second, and when the timer hits zero, it fires an event: StormIsClosing. Your code listens for this signal.

Functions: The Loadout

If you have to type out every step of reloading your weapon every time you press R, that would be tedious. Instead, you have a "Reload" function.

  • Function: A block of code that performs a specific task.
    • Game Analogy: The "Emote" wheel. You select "Floss," and a pre-written sequence of animations plays. You don't animate the character frame-by-frame; you just call the "Floss" function.

Let's Build It

We are going to build a simple Score Counter. When you click a button, your score goes up. It sounds boring, but it's the foundation of every competitive game.

Step 1: The Setup (The Scene Graph)

  1. Open UEFN and create a new Island.
  2. Place a Button device on the map. Name it ChaosButton.
  3. Place a HUD Message device to show the score. Name it ScoreDisplay.
  4. Create a new Verse Script. Name it ScoreScript.

Step 2: The Code

Here is the Verse code. Don't panic—it's just English with strict grammar.

# This is a comment. Verse ignores lines starting with #.
# Think of it as a sticky note for yourself.

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

# We create a "Script" which is the container for our logic.
# It's like creating a new folder for our island's brain.
score_script := class(creative_device):

    # DEVICE REFERENCES: Wire these up in the UEFN Details panel.
    # ChaosButton is a button_device placed on the map.
    @editable
    ChaosButton : button_device = button_device{}

    # ScoreDisplay is a hud_message_device used to show the score.
    @editable
    ScoreDisplay : hud_message_device = hud_message_device{}

    # VARIABLES: These are our "containers."
    # var score : int means "score" is a mutable box that holds whole numbers.
    # It starts at 0.
    var score : int = 0

    # OnBegin runs automatically when the game starts.
    # This is where we connect our events (plug in the wires).
    OnBegin<override>()<suspends> : void =
        # EVENTS: This connects our function to the real world.
        # We "subscribe" OnButtonClicked to the Button's InteractedWithEvent.
        # Think of this as plugging a wire from the Button to our Code.
        ChaosButton.InteractedWithEvent.Subscribe(OnButtonClicked)

    # FUNCTIONS: This is the "logic" for when the button is clicked.
    # button_device events pass the interacting agent as a parameter.
    OnButtonClicked(Agent : agent) : void =
        # This line is the magic.
        # We take the current score, add 1, and put it back in the box.
        set score = score + 1

        # We need to update the visual display.
        # hud_message_device shows a message to all players.
        # note: hud_message_device has no SetText; we use Show() after
        # setting the message text in the Details panel, or print to log.
        Print("Score: {score}")

        # Optional: Let's make it fun!
        # If the score hits 5, let's trigger a random prop effect.
        if (score >= 5):
            SpawnRandomProp()

    # Helper Function: Triggers a random effect when score is 5+
    SpawnRandomProp() : void =
        # We use a random integer in the range 0..99
        RandomVal := GetRandomInt(0, 99)

        # If the random number is low, activate the chaos button's
        # visual pulse as a stand-in effect (device-side feedback).
        # note: actual runtime prop spawning requires a spawner_device
        # wired in the Details panel; use prop_spawner_device.Activate()
        # on an @editable prop_spawner_device for a real implementation.
        if (RandomVal < 20):
            ChaosButton.Enable()```

### Walkthrough: What Just Happened?

1.  **`var score : int = 0`**: We created a variable. It's like your health bar, but instead of health, it's tracking points. The `var` keyword tells Verse this value is allowed to change later.
2.  **`ChaosButton.InteractedWithEvent.Subscribe(OnButtonClicked)`**: This is the **Event Binding**. We told Verse: "Hey, whenever the `ChaosButton` is clicked, run the `OnButtonClicked` function." It's like setting a trap. You don't know *when* the enemy will step on it, but you know *what* will happen when they do.
3.  **`set score = score + 1`**: This is the **Variable Update**. In Verse, you must use the `set` keyword any time you update a `var` after it has been declared. We take the old value, add 1, and save it back to the same variable.
4.  **`Print("Score: {score}")`**: This is where the **Scene Graph** comes in. We reached out to the debug log (visible in the Output Log in UEFN) and printed the current score. In a full build you would wire a `hud_message_device` in the Details panel and call `ScoreDisplay.Show()` to surface the score to players in-game.

## Try It Yourself

Now that you have the basics, try this challenge:

**The Challenge:** Modify the code so that if the score reaches **10**, the screen flashes red (or the button changes color).

**Hint:** You'll need to check the score inside the `OnButtonClicked` function. If `score = 10`, you can activate a separate cinematic or post-process device wired up in the Details panel to give players that red-flash feedback.

*Don't peek at the solution! If you get stuck, remember: Variables change, Events trigger, and Functions do the work.*

## Recap

*   **Scene Graph:** The hierarchy of all objects in your island. Everything is an Entity.
*   **Variables:** Containers for data that changes (like your score or health).
*   **Events:** Signals that trigger code (like a button click or storm closing).
*   **Functions:** Reusable blocks of code that perform specific tasks.

You've just written your first Verse script. You didn't just play the game; you started speaking its language. Go forth and break things (responsibly).

## References

- https://dev.epicgames.com/documentation/en-us/fortnite/campfire-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/grind-vine-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/grind-vine-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/grind-rail-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/grind-rail-device-design-example-in-fortnite-creative

Verse source files

Turn this into a guided course

Add Build Your Own to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.

Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.

Comments

    Sign in to vote, comment, or suggest an edit. Sign in