The Magic Mushroom: A Verse Intro
Tutorial beginner compiles

The Magic Mushroom: A Verse Intro

Updated beginner Code verified

The Magic Mushroom: A Verse Intro

Welcome to your first Verse adventure! We are going to build a tiny, magical healing spot.

You will learn how to make a player get a special item. This item gives them shield. Shield protects players from damage. It is like a blue energy bubble.

What You'll Learn

  • What a Variable is (a box that changes).
  • How to give an Item to a player.
  • How to use a Trigger to start magic.

How It Works

Imagine you are playing a game. You find a glowing mushroom. When you touch it, you feel better. Your shield goes up!

In Verse, we need to tell the game what to do. We use a Variable. Think of a variable as a labeled box. We put the mushroom item inside the box.

We also need a Trigger. This is like a pressure plate. When a player steps on it, the game knows to act.

Here is the plan:

  1. Make a box for the mushroom item.
  2. Make a trigger device.
  3. Tell the trigger: "When someone touches you, give them the mushroom."

Let's build this!

Let's Build It

We will use the Item Granter device. It is a simple tool. It gives items to players.

Copy this code into your Verse script.

# This is a comment. The game ignores it.
# It is for us to read.

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

Create_Mushroom_Grant := class(creative_device):
    # This is our main device.
    # It will grant the mushroom.

    # This is the Item Granter device.
    # Place one in your island and connect it here.
    # Set it to give a Shield Mushroom in its device properties.
    @editable
    item_granter : item_granter_device = item_granter_device{}

    # This is the trigger device.
    # Place one in your island and connect it here.
    # It fires when a player touches the device.
    @editable
    mushroom_trigger : trigger_device = trigger_device{}

    # OnBegin runs automatically when the game starts.
    # We use it to subscribe to the trigger's event.
    OnBegin<override>()<suspends> : void =
        # Tell the trigger to call our function when touched.
        # 'TriggeredEvent' fires and gives us the agent who touched it.
        mushroom_trigger.TriggeredEvent.Subscribe(OnMushroom_Touched)

    # This function runs when a player touches the trigger.
    # 'who' is the agent (player) who touched it.
    OnMushroom_Touched(who : ?agent) : void =
        # We give the item to the player using the Item Granter device.
        # # note: item_granter_device.GrantItem() targets a specific agent.
        if (Agent := who?):
            item_granter.GrantItem(Agent)```

### Walkthrough

*   **`creative_device`**: This is the container for our code. It is like the game piece itself.
*   **`item_granter`**: This is our variable. It holds a reference to an **Item Granter** device placed on the island. The `:=` symbol means "store this here."
*   **`OnBegin`**: This is the function that runs when the game starts. We use it to get everything ready.
*   **`TriggeredEvent.Subscribe(...)`**: This watches the trigger. It waits for a player to touch it.
*   **`item_granter.GrantItem(who)`**: This tells the Item Granter to give its item to the player (`who`).

## Try It Yourself

Now it is your turn!

**Challenge:**
Change the code to give a **Pizza Slice** instead of a mushroom.

**Hint:**
Look for the `item_granter` device on your island. Select it and open its **properties panel**. Change the item it is set to grant from `Shield Mushroom` to `Pizza Slice`. No code change is needed  the device property controls what item is given!

## Recap

You made a magic mushroom! You used a variable to hold the Item Granter device. You used an event to trigger the gift.

Variables are like boxes. Events are like triggers. You are now a Verse creator!

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-consumables-gallery-devices-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/using-items-gallery-devices-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-wild-edible-crafting-consumables-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/verse-api/fortnitedotcom/items/mushroom/creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-restorative-consumables-in-fortnite-creative

Verse source files

Turn this into a guided course

Add Mushroom 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