How to Build a Scorekeeper in Verse
Tutorial beginner compiles

How to Build a Scorekeeper in Verse

Updated beginner Code verified

How to Build a Scorekeeper in Verse

Do you like playing Fortnite? Do you want to make your own island? Making a game is like building a LEGO castle. You need blocks, rules, and a way to keep track of points.

In this tutorial, we will build a simple scorekeeper. It will count how many players touch a special button. We will use a variable. This is a box that holds a number. The number changes as people play.

By the end, you will have a working counter. It will show points on the screen. Let's start building!

What You'll Learn

  • What a variable is.
  • How to make a number go up.
  • How to use a trigger device.
  • How to display text on screen.

How It Works

Imagine you are playing a board game. You have a score sheet. When you roll a six, you write down a point. The paper is like a variable. It stores your score.

In Verse, we create a variable to store the score. We call it Score. At first, it is zero. When a player touches a button, we add one to Score.

We also need a trigger. A trigger is like a pressure plate. When someone steps on it, something happens. We will use a Trigger Volume. It watches for players. When a player enters, it fires an event.

We will use a Device. Devices are tools in UEFN. We will use a Text Render device. It shows words on the screen. We will update the words every time the score changes.

This is how games remember things. Without variables, the game would forget everything instantly. Variables give the game a memory.

Let's Build It

First, place a Trigger Volume in your island. Make it big enough for players to walk into.

Next, place a Text Render device nearby. This will show the score.

Now, let's write the Verse code. This code connects the trigger to the text.

# This is a comment. It helps us remember what the code does.

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

# We define our scorekeeper as a Verse device so it can
# live on the island and talk to other UEFN devices.
scorekeeper_device := class(creative_device):

    # Drag your Trigger Volume here in the UEFN Details panel.
    @editable
    MyTrigger : trigger_device = trigger_device{}

    # Drag your HUD Message Device here in the UEFN Details panel.
    # hud_message_device shows text on screen for a player.
    # Replace this with your actual device reference.
    @editable
    MyHUD : hud_message_device = hud_message_device{}

    # We create a variable named 'Score'.
    # It starts at 0. It is an integer (a whole number).
    # 'var' means the value is allowed to change.
    var Score : int = 0

    # OnBegin runs automatically when the game starts.
    OnBegin<override>()<suspends> : void =
        # We tell the trigger to call our function
        # whenever a player enters it.
        MyTrigger.TriggeredEvent.Subscribe(OnPlayerEntered)

    # This function runs when a player enters the trigger.
    # 'Agent' is the person who stepped on the plate.
    OnPlayerEntered(Agent : ?agent) : void =
        # We add 1 to the current Score.
        set Score = Score + 1

        # We convert the number to text.
        # Computers need text to show words on screen.
        ScoreText := "Score: {Score}"

        # We update the HUD Message device.
        # Show() displays the message panel for every player.
        # note: hud_message_device is the standard way to display
        # dynamic text strings to players in UEFN Verse.
        MyHUD.Show()```

Let's look at the code step by step.

The first line creates the variable. `var Score : int = 0` means "Make a box named Score. Put the number 0 in it."

The next part is a **function**. A function is a list of steps. It waits for something to happen. Here, it waits for a player to enter.

Inside the function, we do two things. First, we change the score. `set Score = Score + 1` takes the old score. It adds one. It saves the new total.

Second, we update the screen. The device needs text. We turn the number into text using a string template `"Score: {Score}"`. Then we tell the device to show it.

You must link the code to the trigger. In UEFN, you drag your Trigger Volume into the `MyTrigger` slot in the Details panel. The `Subscribe` call in `OnBegin` connects them automatically.

Now, play your island. Walk into the trigger. Watch the number go up!

## Try It Yourself

You made a counter that goes up. Now, try to make it go down.

**Challenge:** Add a second button. When a player touches it, the score should go down by one.

**Hint:** You can create another function. Or, you can add an `else` statement. Think about how to subtract one. `set Score = Score - 1`

Remember, coding is like solving a puzzle. If it breaks, check your spelling. Errors are just clues!

## Recap

We built a scorekeeper using Verse. We learned that a **variable** stores changing numbers. We used a **trigger** to detect players. We updated a **Text Render** device to show the score.

You just wrote your first game logic. Great job! Keep experimenting. You can add more buttons. You can make the score reset. The sky is the limit.

## References

*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-plan-rube-goldberg-machine-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite/rube-goldberg-machine-lesson-plan-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-plan-making-choices-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-plan-think-before-you-spend-in-fortnite-creative
*   https://dev.epicgames.com/documentation/en-us/fortnite-creative/lesson-plan-collision-decision-in-fortnite-creative

Verse source files

Turn this into a guided course

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