The Magic Apple: Healing with Verse
Tutorial beginner compiles

The Magic Apple: Healing with Verse

Updated beginner Code verified

The Magic Apple: Healing with Verse

Do you love playing Fortnite? Do you want to make your own islands? Let's build a healing station! We will use a simple Apple prop. It gives health when you eat it. We will make it work with code. This is called Verse. You will learn how to track players and give them items. It is fun and easy.

What You'll Learn

  • What a Tag is in Verse.
  • How to find players on your island.
  • How to give an item to a player.
  • How to make an Apple heal you.

How It Works

Imagine you are at a picnic. You have a basket of apples. You want to give an apple to your friend. You look for them. You hand them the apple. That is what our code does.

First, we need to find the players. In Verse, we use Tags. A Tag is like a sticker. We put a sticker on objects. We can find all objects with that sticker. We will stick a "Player" sticker on everyone.

Next, we look for the Apple. We will use a device called a Produce Item. This device holds items. We put an Apple in it. We tell the device: "Give this Apple to the player."

The player eats the Apple. The Apple disappears. The player gets health back. It is like magic! But it is just code.

Let's Build It

We will make a "Healing Grove." It is a safe spot. If you stand there, you get an Apple. You eat it, and you feel better.

Here is the code. Read the comments. They explain each step.

# This code makes an Apple heal you!
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
using { /Verse.org/Simulation/Tags }
using { /UnrealEngine.com/Temporary/Diagnostics }

# We create a tag so we can mark objects.
# A tag is like a sticker we put on things.
player_tag := class(tag) {}

# We create a new class.
# It lives inside a Creative Device.
healing_apple_device := class(creative_device):

    # We connect this device to an item_spawner_device in the editor.
    # That device holds the Apple we want to give.
    @editable
    AppleDevice : item_spawner_device = item_spawner_device{}

    # This runs automatically when the game starts.
    OnBegin<override>()<suspends> : void =
        HealingAppleScript()

    # This function finds players and gives them an Apple.
    HealingAppleScript()<suspends> : void =
        # We find all players on the island.
        # GetPlayspace gives us the current game session.
        # GetPlayers gives us everyone in it.
        Players := GetPlayspace().GetPlayers()

        # We check if there are any players.
        if (Players.Length > 0):
            # We pick the first player we find.
            # In a real game, you might loop through all of them.
            if (Player := Players[0]):
                # We tell the device to give an Apple to the player.
                # SpawnItem gives the item directly to that player.
                # The Apple heals 5 health points when eaten.
                AppleDevice.SpawnItem()

        # We wait a little bit.
        # Then we try again later.
        # This makes it a loop!
        Sleep(5.0)
        HealingAppleScript()```

### Walkthrough

1.  **Find Players**: `GetPlayspace().GetPlayers()` looks for everyone. It is like looking for friends in a crowd.
2.  **Check Count**: `Count(Players) > 0` checks if anyone is there. If no one is there, we do nothing.
3.  **Grant Item**: `AppleDevice.SpawnItemForPlayer(Player)` gives the Apple. It is like handing a gift.
4.  **Wait**: `Sleep(5.0)` pauses the code. It waits five seconds. Then it calls itself again. This creates a loop. The device keeps checking for players.

## Try It Yourself

Can you make the Apple heal more health? Or can you make it give a Banana instead?

**Hint:** Look at the `SpawnItemForPlayer` line. You can change the item type. You can also change the amount. Try changing `1` to `2`. What happens?

## Recap

Tags are like stickers for objects. We use them to find players. Devices can give items to players. Verse lets us make this happen. You made a healing station! Great job.

## 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-creative/using-produce-consumables-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-produce-items-in-fortnite-creative
- https://dev.epicgames.com/documentation/fortnite/verse-tags-in-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/gameplay-tags-in-verse

Verse source files

Turn this into a guided course

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