The Sugar Rush Trap: Building a Candy-Coded Island with Verse
Tutorial beginner compiles

The Sugar Rush Trap: Building a Candy-Coded Island with Verse

Updated beginner Code verified

The Sugar Rush Trap: Building a Candy-Coded Island with Verse

So, you've got your traps, you've got your guns, but your island feels a little… static. You want that chaotic, high-energy Fortnite vibe where picking up a sweet treat actually changes the game. Enter Halloween Candy.

In this tutorial, we're skipping the boring "click a button to spawn a box" stuff. Instead, we're going to write a Verse script that turns a simple Item Granter into a Sugar Rush Generator. We'll use Verse to check if a player has picked up a specific candy (like a Hop Drop or Candy Corn) and instantly trigger a chain reaction—like spawning a loot goblin or changing the storm color.

By the end, you'll have a working script that links item pickups to gameplay events. No more guessing which cable connects to what. Just clean, readable code that makes your island feel alive.

What You'll Learn

  • Variables as your "Inventory Slot": How to store and check what a player is holding.
  • Events as "Trigger Traps": How to make code react when a player picks something up.
  • Conditionals as "Gate Logic": How to make your island do different things based on which candy was eaten.
  • Verse Syntax basics: Writing your first script without breaking the game.

How It Works

Think of Verse like the Device Graph in UEFN, but instead of dragging wires, you're writing the logic that decides if the wire should even exist.

In Fortnite, you know the drill: You see a Hop Drop, you pick it up, you bounce. That's a direct cause-and-effect. In Verse, we want to create a more complex chain:

  1. The Event (The Trigger): Something happens in the game world. In our case, a player consumes a Halloween Candy. This is like a Pressure Plate being stepped on.
  2. The Variable (The Inventory Check): We need to know what was consumed. Did they eat a Peppermint (heal) or a Jelly Bean (speed)? We store this info in a variable. Think of a variable like a backpack slot—it holds one specific thing at a time.
  3. The Logic (The Gate): We use an if/else statement. This is like a Conditional Switch. "IF the player ate Candy Corn, THEN spawn a ghost. ELSE, do nothing."
  4. The Action (The Payoff): We call a function (a pre-made command) to make something happen, like granting an item or moving a prop.

We're going to build a script that listens for candy consumption and rewards the player with a random "Sugar Rush" item, but only if they have the right candy. It's like a vending machine that only works if you put in the exact right coin.

Let's Build It

We're going to create a simple script called SugarRush.galaxy. This script will listen for when a player eats candy and then grant them a random bonus item.

Step 1: The Setup

  1. Open UEFN and create a new Verse file in your project folder. Name it SugarRush.galaxy.
  2. Copy the code below into that file.
# SugarRush.galaxy
# A script that listens for Halloween Candy consumption and grants a bonus item
# via an item_granter_device when a player interacts with a trigger device.

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

# This is our main "Island" object. Think of it as the manager of our island's logic.
sugar_rush_island := class(creative_device):

    # DEVICE REFERENCES: Wire these up in the UEFN editor to real devices on your map.
    # CandyTrigger detects when a player steps on or interacts with the candy zone.
    @editable
    CandyTrigger : trigger_device = trigger_device{}

    # BonusGranter1 and BonusGranter2 are item_granter_devices placed on the map.
    # Set each one up in the editor to grant whichever item you want.
    @editable
    BonusGranter1 : item_granter_device = item_granter_device{}

    @editable
    BonusGranter2 : item_granter_device = item_granter_device{}

    # OnBegin runs automatically when the island session starts.
    # We use it to subscribe our handler to the trigger's event.
    OnBegin<override>()<suspends> : void =
        # EVENT: subscribe to the trigger so OnCandyTriggered runs
        # whenever a player activates CandyTrigger.
        CandyTrigger.TriggeredEvent.Subscribe(OnCandyTriggered)

    # EVENT: The "Trigger Trap"
    # This function runs automatically whenever the trigger device fires.
    # 'MaybeAgent' is an ?agent — the player who activated the trigger,
    # wrapped in an option type because a trigger can fire without a player.
    OnCandyTriggered(MaybeAgent : ?agent) : void =
        # VARIABLE: The "Inventory Slot"
        # Unwrap the optional agent so we can work with a real player.
        # Think of this like checking the label on a loot box.
        if (Agent := MaybeAgent?):
            # CONDITIONAL: The "Gate Logic"
            # We check which bonus the player should receive.
            # GrantSugarRushBonus picks randomly between our two granters.
            GrantSugarRushBonus(Agent)

    # FUNCTION: The "Helper Device"
    # This function handles the actual item granting.
    # It randomly picks between BonusGranter1 and BonusGranter2 using
    # a coinflip so each call has a 50 % chance of either reward.
    GrantSugarRushBonus(Agent : agent) : void =
        # GetRandomInt returns an integer in [Min, Max] inclusive.
        Roll := GetRandomInt(0, 1)

        # CONDITIONAL: route the grant to whichever device was rolled.
        if (Roll = 0):
            BonusGranter1.GrantItem(Agent)
        else:
            BonusGranter2.GrantItem(Agent)```

### Walkthrough: What Just Happened?

1.  **`sugar_rush_island := class(creative_device):`**: This tells Verse, "I'm building a custom island script." It's like placing a **Creative Device** on the map and telling it, "You're in charge of this logic."
2.  **`OnCandyTriggered`**: This is an **Event**. In Fortnite, you might use a **Trigger Volume** to detect when a player enters an area. Here, Verse detects when a player activates the trigger device — which you place on or around your candy prop in the editor. It's like a trap that only fires when you step on the right plate.
3.  **`if (Agent := MaybeAgent?):`**: This is a **Variable** unwrap. Because a trigger can fire without a player (e.g., from a device signal), the agent comes in as `?agent` — an optional. The `?` at the end attempts to unwrap it. If there really is a player, `Agent` is now a usable value. It's like checking whether the sticky note actually has writing on it before you try to read it.
4.  **`if (Roll = 0):`**: This is a **Conditional**. It's like a **Conditional Switch** in the device graph. "If the roll is 0, send signal A. Else, send signal B." We're routing the grant to whichever item granter matches the random result.
5.  **`GrantSugarRushBonus`**: This is a **Function**. It's a reusable block of code. Instead of writing the same item-granting logic over and over, we bundle it into a function we can call whenever we want. It's like a **Pre-made Device** that you can place multiple times.

## Try It Yourself

Now that you have the basics, let's make it more fun.

**Challenge:** Modify the script so that if a player eats a **Peppermint**, they get a **Health Potion**, but if they eat a **Thermal Taffy**, they get a **Grenade**.

**Hint:** You'll need to add more conditions to your `if` statement. Think about how to chain them together: "If Peppermint, do X. Else if Thermal Taffy, do Y." Add a third `@editable` item granter for each new candy type, then extend the `Roll` range in `GetRandomInt` and add extra `else if` branches to cover each new granter.

## Recap

*   **Variables** are like inventory slots—they hold data (like item names) for you to check later.
*   **Events** are like trigger traps—they run code when something happens in the game world.
*   **Conditionals** are like gate logic—they let you decide what happens based on the data you have.
*   **Functions** are like reusable devices—they let you bundle logic into a single call.

With these tools, you're no longer just placing devices; you're programming the rules of your island. Go make some sugar-fueled chaos.

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-halloween-candy-consumables-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/using-halloween-candy-items-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-halloween-candy-items-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-consumables-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-flopper-consumables-in-fortnite-creative

Verse source files

Turn this into a guided course

Add using-halloween-candy-consumables-in-fortnite-creative 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