Build a Teamwork Treasure Hunt
Tutorial beginner compiles

Build a Teamwork Treasure Hunt

Updated beginner Code verified

Build a Teamwork Treasure Hunt

Welcome, young creators! Today, we are going to build a mini-game together. We will make a "Teamwork Treasure Hunt." You will write code to help players work together. This is not just about coding. It is about solving puzzles. It is about being kind. It is about thinking fast.

You will learn how to track player progress. You will learn how to share information between players. This helps everyone win. Let's start building!

What You'll Learn

  • Teamwork in Code: How to make one player's action help another.
  • Shared State: Using a special box to store data for everyone.
  • Winning Together: Creating a goal that requires two people.
  • 21st Century Skills: Practicing communication and critical thinking.

How It Works

Imagine you are playing a board game. You roll the dice. You move your piece. But what if your friend needs to move too? In Fortnite Creative, players are like pieces on a board. They can move separately. But their actions can be connected.

We need a way for Player 1 to tell Player 2 what happened. We use something called a Variable. A variable is like a labeled box. You put something inside. You can change what is inside.

Here is the plan. We will make two switches. Switch A is for Player 1. Switch B is for Player 2. When Player 1 flips Switch A, a light turns on. But the light only stays on if Player 2 also flips Switch B. This is collaboration. It is also critical thinking. You must think: "I need my friend to help me."

We will use a Global Variable. This is a box that everyone can see. It lives in the game world. It does not belong to just one player. It belongs to the team.

Let's Build It

We will build a simple system. There are two switches. There is one treasure chest. The chest opens only when both switches are on.

Step 1: Place Your Objects

  1. Place two Switches in the world. Name one "Switch A" and one "Switch B".
  2. Place a Prop Mover or a Chest nearby. This is the treasure.
  3. Make sure the treasure is closed or hidden at first.

Step 2: The Code

We need a script. This script watches the switches. It checks if both are on. If yes, it opens the treasure.

Copy this code into a new Verse script. Attach it to the treasure object.

# This script makes a treasure chest open when two switches are on.

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

# This is our main script block.
# It runs when the game starts.
teamwork_treasure_hunt := class(creative_device):

    # Wire these two properties to your Switch devices in the UEFN editor.
    @editable
    Switch_A_Device : switch_device = switch_device{}

    @editable
    Switch_B_Device : switch_device = switch_device{}

    # Wire this property to your Prop Mover device in the UEFN editor.
    @editable
    Treasure_Mover : prop_mover_device = prop_mover_device{}

    # Wire this property to your Button Solver / HUD Message Device for feedback.
    # We use a hud_message_device to show on-screen text to players.
    @editable
    Message_Device : hud_message_device = hud_message_device{}

    # This variable holds the state of the switches.
    # It is a "boolean". A boolean is true or false.
    # We start with both switches being "off".
    # var means we can change the value later.
    var Switch_A_State : logic = false
    var Switch_B_State : logic = false

    # This function runs when the script starts.
    OnBegin<override>()<suspends> : void =
        # We listen for events from Switch A.
        # When Switch A is turned on, we run our handler.
        Switch_A_Device.TurnedOnEvent.Subscribe(OnSwitchAActivated)

        # We listen for events from Switch B.
        # When Switch B is turned on, we run our handler.
        Switch_B_Device.TurnedOnEvent.Subscribe(OnSwitchBActivated)

    # This handler runs when Switch A is turned on.
    OnSwitchAActivated(Agent : agent) : void =
        set Switch_A_State = true
        # Show a message so Player 1 knows the partner is needed.
        Message_Device.Show(Agent)
        CheckWinCondition()

    # This handler runs when Switch B is turned on.
    OnSwitchBActivated(Agent : agent) : void =
        set Switch_B_State = true
        CheckWinCondition()

    # This function checks if we won.
    CheckWinCondition() : void =
        # If BOTH states are true, we win!
        if (Switch_A_State? and Switch_B_State?):
            OpenTreasure()

    # Helper function to open treasure using the Prop Mover device.
    OpenTreasure() : void =
        # Activate the Prop Mover. It will move the treasure to its end position.
        # Set the Prop Mover's end position above the chest in the UEFN editor.
        Treasure_Mover.Begin()
        Print("Treasure opened! Great teamwork!")```

### Walkthrough

1.  **`teamwork_treasure_hunt := class(creative_device)`**: This creates our script. Think of it as a new type of device. All UEFN scripts extend `creative_device`, not `Verse.Script`.
2.  **`@editable`**: This special tag lets you connect real devices from the UEFN editor to your script. You will see these as slots you can fill in the editor panel.
3.  **`var Switch_A_State : logic = false`**: We create two boxes. They start empty (false). The word `var` means the value can be changed later. The type `logic` is Verse's name for a true/false boolean.
4.  **`OnBegin`**: This is where the game starts. We use `Subscribe` to set up listeners on real device events.
5.  **`TurnedOnEvent.Subscribe(...)`**: This is the real event on a `switch_device`. It fires when a player flips the switch on. We give it the name of a function to call.
6.  **`set Switch_A_State = true`**: In Verse, you must write `set` before changing a `var` variable. This is how Verse knows you mean to update the box.
7.  **`CheckWinCondition`**: This is the brain. It asks: "Are both boxes true?" If yes, we open the treasure.
8.  **`if (Switch_A_State? and Switch_B_State?)`**: The `?` after a `logic` variable is how Verse checks whether it is true inside an `if` statement. This is an **If Statement**. It is like a fork in the road. If the path is clear, we go forward. If not, we wait.
9.  **`Treasure_Mover.MoveToEnd()`**: This calls the real `prop_mover_device` function that slides the prop to its end position, revealing the treasure.

## Try It Yourself

Now it is your turn! The code above is a start. But it is not connected to real devices yet.

**Challenge:**
1.  In the UEFN editor, find the **Switch** devices.
2.  Connect them to the script.
3.  Make the treasure chest actually open when the script says "Win".

**Hint:**
You need to tell the script which Switch is which. Use the **Event Graph** or pass the devices into the script. You can also use a **Prop Mover** device for the treasure. Set it to move up when triggered.

Can you make it so that if Player 1 flips their switch, a message appears saying "Waiting for Partner"? This helps with **communication**.

## Recap

You built a teamwork machine! You learned that code can connect players. You used variables to remember who did what. You practiced **collaboration**. You practiced **critical thinking**. You are now a 21st-century creator. Keep building!

## References

- https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-plan-goat-getaway-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/sdg-goat-getaway-lesson-plan-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-plan-inclusive-island-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/sdg-inclusive-island-sdg-lesson-plan-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-plan-conditional-statements-in-fortnite-creative

Verse source files

Turn this into a guided course

Add INTERDISCIPLINARY AND 21ST CENTURY CONNECTIONS 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