Build a Secret Cave with a Campfire
Tutorial beginner compiles

Build a Secret Cave with a Campfire

Updated beginner Code verified

Build a Secret Cave with a Campfire

Imagine you are building a secret hideout in Fortnite. You want players to find a hidden cave. Inside, there is a warm campfire. This tutorial shows you how to make that happen. We will use Verse to control the magic. You will learn how to change things when a player touches them.

What You'll Learn

  • How to create a variable. This is a box that stores a number.
  • How to use a function. This is a set of instructions.
  • How to make a device talk to your code.
  • How to build a simple, playable secret spot.

How It Works

Think of your island like a big toy box. Inside the box are many toys. These are called entities. An entity is just an object in your game. It can be a rock, a player, or a campfire.

We need a way to remember if the campfire is lit. We use a variable. A variable is like a sticky note. You write a number on it. Later, you can change that number.

Let's say the variable is called is_lit.

  • If is_lit is 0, the fire is out.
  • If is_lit is 1, the fire is on.

We also need a function. A function is like a recipe. It tells the computer what to do. When a player walks into the cave, we call this recipe. The recipe checks the sticky note. If the fire is off, it turns it on!

We also need events. An event is a trigger. It is like a doorbell. When someone presses the doorbell, you know someone is there. In Fortnite, we use triggers. A trigger is a special zone. When a player enters the zone, the event happens.

Let's Build It

We will build a small cave. We will add a trigger. When a player steps on the trigger, the campfire lights up.

Here is the Verse code. Copy this into your Verse editor.

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

# This is our script. It lives on the cave device.
CaveScript := class(creative_device):

    # Wire the trigger device in the UEFN editor.
    @editable
    CaveTrigger : trigger_device = trigger_device{}

    # Wire the campfire device in the UEFN editor.
    # note: campfire_device is the real Verse type for the Campfire Device.
    @editable
    Campfire : campfire_device = campfire_device{}

    # This variable is our sticky note.
    # It starts as false (0). The fire is off.
    var IsFireLit : logic = false

    # OnBegin runs once when the game starts.
    # We use it to connect the doorbell to the recipe.
    OnBegin<override>()<suspends> : void =
        # This binds the function to the trigger.
        # It means: "When the trigger is entered, run OnPlayerEnter."
        CaveTrigger.TriggeredEvent.Subscribe(OnPlayerEnter)

    # This function is the recipe.
    # It runs when a player enters the trigger zone.
    OnPlayerEnter(MaybeAgent : ?agent) : void =
        # Check if the fire is already lit.
        if (IsFireLit = false):
            # Turn the fire on!
            # We set our sticky note to true (1).
            set IsFireLit = true

            # This line lights the fire in the game.
            Campfire.Enable()

            # Tell the player something cool happened.
            Print("You found the secret campfire!")```

### Walkthrough

1.  **`var IsFireLit : logic = false`**: We create a variable. It is a boolean. A boolean is a switch. It is either on or off. We start with it off.
2.  **`OnPlayerEnter(Agent : agent) : void`**: We define our function. It waits for a trigger event.
3.  **`if (IsFireLit = false):`**: We check our sticky note. Is the fire off?
4.  **`set IsFireLit = true`**: If it is off, we flip the switch. Now the fire is on.
5.  **`Campfire.Enable()`**: This talks to the campfire device. It tells it to show flames.
6.  **`CaveTrigger.AgentEntersEvent.Subscribe(OnPlayerEnter)`**: This connects the doorbell (trigger) to the recipe (function).

## Try It Yourself

Now you try! Build your own secret spot.

**Challenge:**
1.  Build a small room with a door.
2.  Place a **Trigger** inside the room.
3.  Place a **Prop Mover** (a moving platform) outside.
4.  Write code so that when a player enters the room, the platform moves up.

**Hint:**
You can use the same `if` statement. But instead of `Enable()`, you will use `PropMover.MoveToNextStop()`. Check the device settings for the exact name of the function.

## Recap

You built a secret cave! You learned about variables. Variables store info like "is the fire on?". You learned about functions. Functions are recipes for actions. You learned about events. Events are triggers that start the action. Great job, coder!

## 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/air-vent-device-design-examples-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-creative/grind-vine-device-design-example-in-fortnite-creative

Verse source files

Turn this into a guided course

Add Build It Yourself 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