---
title: "Verse Basics — Learning Path"
date: "2026-06-21"
category: "education"
excerpt: "Welcome to Verse programming for UEFN! In this learning path, you'll discover what Verse is, why it was created for Fortnite Creative, and how to write your own code to make amazing things happen on your island. By the end, you'll have written your very first device script and seen it work live in the game."
level: "grade4-6"
estimated_minutes: 180
author: "Verse Cortex"
status: "published"
---

# Verse Basics

Welcome to Verse programming for UEFN! In this learning path, you'll discover what Verse is, why it was created for Fortnite Creative, and how to write your own code to make amazing things happen on your island. By the end, you'll have written your very first device script and seen it work live in the game.

**Reading level:** grade4-6  ·  **Estimated time:** 180 min  ·  **Lessons:** 6

## What You'll Learn

- Understand what Verse is and why it's a powerful tool for game creation in UEFN
- Write and run basic Verse programs that print messages and store information in variables
- Create your own functions and use control flow (if statements and loops) to make decisions and repeat actions
- Build a complete Verse device script and add it to your Fortnite island
- Debug and playtest your code to see it working in a real game

---

## Lesson 1: What is Verse and Why Use It?

**Objectives:**

- Explain what Verse is and why it was made for games
- Describe how UEFN and Fortnite Creative work together
- Identify what Verse lets you do that regular Creative devices cannot
- Recognize where Verse code lives inside a UEFN project

### 🎮 Welcome to Verse — Your Game's Secret Superpower!

Have you ever played a Fortnite Creative island and thought, *"I wish this game had a rule that didn't exist yet"*? That's exactly why **Verse** was invented!

---

### What Is Verse?

**Verse** is a **programming language**. Think of a programming language like a recipe book — it gives you a special way to write instructions that a computer can read and follow.

But Verse isn't just any recipe book. It was built *specifically for video games*. That makes it extra great for making things happen inside Fortnite!

---

### What Is UEFN?

**UEFN** stands for **Unreal Editor for Fortnite**. It's a super-powered building tool made by Epic Games. Imagine Fortnite Creative is a LEGO set. UEFN is like getting the *pro builder kit* — way more pieces and tools!

Here's how the pieces fit together:

- 🟦 **Fortnite Creative** — the regular island builder most players know
- 🟧 **UEFN** — the pro-level editor with extra features
- 🟩 **Verse** — the programming language that lets you write *custom rules* for your island

Together they make a team. You build the island in UEFN, and Verse tells the island how to *behave*.

---

### Why Can't I Just Use Devices?

Great question! In Fortnite Creative, you already have **devices**. A device is a special object that does one job — like a **Trigger** that fires when a player walks on it, or a **Score Manager** that tracks points.

Devices are awesome. But they only connect in **set ways**. It's like having LEGO pieces that only snap together in one direction. You can build cool things, but you can't build *everything*.

**Verse fills the gap.** It lets you write brand-new rules — things no device can do on its own.

Here are some things Verse can help you do that devices *can't* easily do alone:

- 🎯 **Complex interactions** — like a trap that only activates for *one specific player*
- ⏱️ **Precise timing** — like starting a countdown the moment the *third* player joins
- 📋 **New game rules** — like a tag game where "it" switches every 30 seconds
- 🔄 **Dynamic changes** — like making the island get harder as the score goes up

---

### Verse and the Future 🚀

Here's a cool bonus fact: Verse isn't just for Fortnite. Epic Games is building it into **Unreal Engine 6**, which is one of the most popular game-making tools in the whole world. Learning Verse now means you're learning a skill that will grow with you into real game development!

---

### How Does Verse Fit Into UEFN?

Inside UEFN, you write Verse code in special files called **.verse files**. Think of each file like a page in your recipe book. Each page has instructions for one part of your island.

Your Verse file connects to **devices** on your island. When something happens in the game — like a player stepping on a trigger — your Verse code wakes up and runs its instructions. 

It's like a sleeping robot that jumps to life the moment it hears the signal! 🤖

### Worked Example

### 🔬 Let's Look at a Real Verse File

Below is the simplest possible Verse device you can make in UEFN. It connects to your island and prints a message when the game starts. This is what a real `.verse` file looks like!

```verse
# This tells Verse: "this file is part of my island project"
using { /fortnite/devices }
using { /verse.org/simulation }
using { /verse.org/native }

# A "class" is like a blueprint for a custom device.
# 'creative_device' means this is a device that can live on your island.
my_first_device := class(creative_device):

    # 'OnBegin' is a special function that runs the moment your game starts.
    # Think of it like the starting pistol at a race — BANG, go!
    OnBegin<override>()<suspends>:void=
        Print("My island is alive! Verse is working! 🎉")
```

### 🚶 Walk Through It Step by Step

1. **`using { /fortnite/devices }`** — This line imports tools from Fortnite. It's like opening your toolbox before you start building.

2. **`my_first_device := class(creative_device):`** — This creates a **custom device** (your own special island gadget). The `:=` symbol means "make this thing and name it."

3. **`OnBegin<override>()<suspends>:void=`** — This is a **function** (a named set of instructions). `OnBegin` is the name Verse uses for "run this when the game begins."

4. **`Print("My island is alive! ...")`** — This sends a message to the output log. It's how you check that your code is running. Think of it as your island waving hello! 👋

> 💡 **In UEFN:** After writing this, you drag your device onto the island in the editor, hit **Build Verse**, then **Play** — and you'll see your message appear in the output log!

### Try It Yourself

### 🛠️ Your Turn — Build Your First Island Hello!

**Goal:** Set up a UEFN project and get a Verse device running on your island.

**Steps to follow:**

1. Open **UEFN** and create a **new project** using a blank island template.
2. In the top menu, go to **Verse > Create New Verse File**. Name it `my_first_device`.
3. Look at the worked example above. Type the code into your new file. *(Don't copy-paste — typing it helps your brain learn it!)*
4. In UEFN, click **Verse > Build Verse** to check for errors.
5. Drag your new device from the **Content Browser** onto the island floor.
6. Press **Launch Session** to play. Open the **Output Log** and look for your printed message!

**🎯 Checkpoint:** Can you see your message in the Output Log? If yes — you just ran your very first Verse program! 🥳

---

**🌶️ Bonus Challenge:**

Can you change the text inside `Print(...)` to say *your own name* and something fun? For example:

```verse
Print("Alex's island is LIVE! Let's gooo! 🚀")
```

> 💡 **Hint:** The message goes between the two quotation marks `" "`. Only change what's inside those marks — leave everything else exactly the same!

### Quiz

1. What is Verse?
   - A. A new Fortnite weapon skin
   - B. A programming language for making game rules in UEFN
   - C. A device you place on your island like a trigger
   - D. A type of Fortnite Creative map

2. Why would a game creator use Verse instead of just using devices?
   - A. Because devices don't work in UEFN at all
   - B. Because Verse makes your island look prettier
   - C. Because devices can only connect in set ways, but Verse lets you create brand-new rules
   - D. Because Verse is faster to learn than placing devices

3. In Verse, what does the special function 'OnBegin' do?
   - A. It ends the game when a player wins
   - B. It runs your instructions the moment the game starts
   - C. It places a new device on the island
   - D. It saves your Verse file to the computer

4. What does UEFN stand for?
   - A. Universal Engine For Navigating
   - B. Unique Effects For New games
   - C. Unreal Editor for Fortnite
   - D. Unreal Engine Fortnite Network

**Answer key:**

1. B — Verse is a programming language — like a special recipe book of instructions — built specifically for making game rules and interactions in UEFN and Fortnite!
2. C — Devices are great, but they only snap together in pre-set ways — like LEGO pieces with one direction. Verse lets you invent completely new rules that no device can do on its own!
3. B — OnBegin is like the starting pistol at a race. The moment the game begins, Verse runs whatever instructions you put inside OnBegin. That's why it's perfect for setup tasks!
4. C — UEFN stands for Unreal Editor for Fortnite. It's the pro-level building tool that combines Unreal Engine's power with Fortnite Creative — and it's where you write Verse code!

### Recap

### 🌟 Great Work — Here's What You Learned!

**Verse** is a programming language made just for games, and it works inside **UEFN** — the pro builder tool for Fortnite. Regular Creative **devices** are powerful, but they can only connect in set ways. Verse fills that gap by letting you write **brand-new rules** your island has never seen before. You even wrote your very first Verse device and sent a message from your island — that's a huge first step! 🎉

**Sources:**

- /docs/documentation/en-us/uefn/unreal-editor-for-fortnite-documentation
- /docs/documentation/en-us/fortnite/verse-language-get-started-in-unreal-editor-for-fortnite
- /docs/documentation/fortnite/verse-language-get-started-in-unreal-editor-for-fortnite

---

## Lesson 2: Run Your First Verse Program

**Objectives:**

- Open UEFN, create a new project using the Verse Device template, and add a Verse device to your island.
- Read and understand the basic parts of a Verse program (the device class and the OnBegin function).
- Run your island and find your program's output in the Log.
- Modify the Verse code to print your own custom message and see it appear in the Log.

### 🎮 Welcome to Your First Verse Program!

You are about to write real code — the same kind of code that powers Fortnite islands! The language is called **Verse**. It is Epic Games' programming language for UEFN (Unreal Editor for Fortnite).

Don't worry if you have never coded before. We will go step by step. You've got this! 🚀

---

### 🧰 What Is UEFN?

**UEFN** stands for **Unreal Editor for Fortnite**. Think of it like a giant toy factory. You use it to build your own Fortnite islands. Verse is the language you use to give your island a "brain" — to make things *happen* in your game.

---

### 📦 What Is a Verse Device?

A **device** is a special object you place on your island. Think of it like a LEGO brick with a tiny computer inside. When the game starts, the device's code runs automatically.

In this lesson, your device will print a message. **Printing** doesn't mean paper — it means showing text in a special log screen inside the game. It's how programmers check that their code is working.

---

### 🗂️ Setting Up Your Project

Here's how to get started in UEFN:

1. Open UEFN. In the **Project Browser**, click **Feature Examples**.
2. Find and click **Verse Device** template, then give your project the name **MyVerseProject**. Click **Create**.
3. In the **Menu Bar** at the top, go to **Verse > Verse Explorer**. This panel shows all your Verse files — like a folder for your code.
4. Right-click your project name in Verse Explorer. Choose **Add new Verse file to project**.
5. In the window that pops up, click **Verse Device**, then click **Create**. This creates a starter code file called **hello_world_device.verse**. 🎉
6. Go to **Verse > Build Verse Code** so UEFN notices your new file.
7. Open the **Content Browser** (bottom of the screen). Find your **hello_world_device** and **drag it into your level** (the big 3D world in the middle of UEFN).

> 💡 **Level** means the map or island you are building. Dropping the device into it is like placing a LEGO brick on your baseplate.

---

### 🏃 Running Your Island

1. Click **Launch Session** in the toolbar. A window may ask you to save — click **Save Selected**.
2. When it loads, open the Main Menu and click **Start Game**.
3. Once in the game, press **Escape**, click **Island Settings**, then click **Log** at the top.
4. Look for the line that says **"Hello, world!"** followed by **"2 + 2 = 4"**. Those came from your Verse code! Your program ran! 🥳

---

### 🔍 What Is the Log?

The **Log** is like a notebook the game keeps while it runs. Your code can write notes into it. This is super useful — it tells you "Hey, my code ran!" or "Here is what happened." Programmers call this **logging** or **printing to the log**.

---

### ✏️ Modifying Your Code

Now let's look at the code and change it!

1. Go to **Verse > Verse Explorer** and double-click **hello_world_device.verse**. It opens in **VS Code** (Visual Studio Code) — a free program for writing code. Think of VS Code like a super-smart notepad.
2. You will see the starter code. We will look at it together in the next section.
3. You can add a new `Print` line to show your own message. After you edit and save the file, go back to UEFN, click **Verse > Build Verse Code**, and launch your session again to see your changes!

---

### 🔑 Key Words to Know

| Word | What It Means |
|---|---|
| **Verse** | The coding language for Fortnite islands |
| **Device** | A code-powered object you place on your island |
| **Log** | A screen that shows messages from your code |
| **Print** | Sending a text message to the Log |
| **Build Verse Code** | Telling UEFN to read your latest code changes |

### Worked Example

### 📖 Let's Read the Starter Code

When you open **hello_world_device.verse** in VS Code, you see something like this:

```verse
# This is your first Verse device!
# Lines that start with # are called "comments."
# Comments are notes for humans — the computer ignores them.

using { /Fortnite.com/Devices }       # Lets us use UEFN devices
using { /Verse.org/Simulation }        # Lets us use game timing tools
using { /UnrealEngine.com/Temporary/Diagnostics }  # Lets us use Print

# A "class" is like a blueprint for your device.
# creative_device is the base type — all island devices inherit from it.
hello_world_device := class(creative_device):

    # OnBegin is a special function that runs automatically when the game starts.
    # Think of it like the "Start" signal on a race — when the game goes, this runs!
    OnBegin<override>()<suspends>:void=
        Print("Hello, world!")    # Shows "Hello, world!" in the Log
        Print("2 + 2 = {2 + 2}") # Shows "2 + 2 = 4" — Verse does the math!
```

---

### 🧩 Breaking It Down

- **`using { ... }`** — These lines are like packing your backpack before school. They load tools you need, such as the ability to `Print` text.

- **`hello_world_device := class(creative_device):`** — This creates a **class**. A class is a *blueprint*. Just like a blueprint for a house tells builders what to build, this blueprint tells UEFN what your device does. It *inherits* from `creative_device`, meaning it's built on top of an existing UEFN device type — like inheriting your parent's eye color, but for code!

- **`OnBegin<override>()<suspends>:void=`** — This is a **function**. A function is a set of steps. `OnBegin` is special — UEFN calls it automatically the moment the game starts. It's like the "GO!" in a race.

- **`Print("Hello, world!")`** — This is a **function call**. You are telling Verse: "Run the Print function and give it this message." The message appears in the Log.

- **`Print("2 + 2 = {2 + 2}")`** — The curly braces `{ }` inside a Print message let you put math or code right inside your text! Verse calculates `2 + 2` and writes `4` for you.

---

### 🎯 What You Should See in the Log

After you Launch Session and Start Game, open the Log and you'll find:

```
Hello, world!
2 + 2 = 4
```

That means YOUR code ran in a real Fortnite island. You are officially a Verse programmer! 🌟

### Try It Yourself

### 🛠️ Your Turn — Make It Your Own!

You have seen how `Print` works. Now let's make the program say something new!

**Your challenge:**

1. Open **hello_world_device.verse** in VS Code.
2. Inside `OnBegin`, **add two new `Print` lines** below the existing ones.
   - One line should print **your name** (example: `"My name is Alex!"`)
   - One line should print **a math fact using `{ }`** (example: `"5 + 3 = {5 + 3}"`)
3. Save your file in VS Code (press **Ctrl+S** on Windows or **Cmd+S** on Mac).
4. In UEFN, go to **Verse > Build Verse Code**.
5. Click **Launch Session**, start the game, and check the **Log** for your new messages!

---

**🤔 Hints:**

- Every `Print` line goes *inside* `OnBegin`, with the same indentation (spacing) as the other Print lines.
- Make sure your message text is always inside `"quotation marks"`.
- If you want to show math, wrap it in `{ }` inside the quotes — like `"10 - 4 = {10 - 4}"`.
- If the Log doesn't show your new line, double-check that you saved the file AND ran **Build Verse Code** again!

---

**🌟 Bonus Challenge:**

Can you add a third `Print` line that says how old you are? Like: `"I am 11 years old!"`

(No math needed — just type the number right in the message!)

### Quiz

1. What does the `Print` function do in Verse?
   - A. It sends your code to a printer.
   - B. It shows a text message in the game's Log screen.
   - C. It places a new device on your island.
   - D. It starts the game automatically.

2. What is the name of the special function that runs automatically when your game starts?
   - A. StartGame
   - B. OnBegin
   - C. LaunchSession
   - D. Print

3. You want your Print message to show the result of 10 × 2. Which line of code is correct?
   - A. Print(10 * 2)
   - B. Print("10 times 2 = 10 * 2")
   - C. Print("10 times 2 = {10 * 2}")
   - D. Print{"10 times 2"}

4. After you save changes to your Verse file in VS Code, what must you do in UEFN before the changes show up in your game?
   - A. Drag the device into the level again.
   - B. Go to Verse > Build Verse Code.
   - C. Restart your computer.
   - D. Delete the old device and make a new one.

**Answer key:**

1. B — In Verse, `Print` sends a text message to the Log — a special screen that shows notes from your code. No paper involved! 📝
2. B — `OnBegin` is the function UEFN calls the moment the game starts — like a starting pistol at a race. All the code inside it runs right away!
3. C — You put the math inside curly braces `{ }` inside the quotes. Verse calculates the math and puts the answer right into your message. So `{10 * 2}` becomes `20`!
4. B — You always need to go to **Verse > Build Verse Code** after saving changes. This tells UEFN to read your latest code. Think of it as pressing 'refresh' so UEFN sees your updates!

### Recap

### 🏆 Great Work — Let's Recap!

You just wrote and ran your very first Verse program inside a real Fortnite island! 🎉 You learned that a **Verse device** is a code-powered object you drop into your level, and that the **`OnBegin` function** runs your code the moment the game starts. You used **`Print`** to send messages to the **Log**, and you even used curly braces `{ }` to do live math inside a message. Keep experimenting — every great game developer started exactly where you are right now! 🌟

**Sources:**

- /docs/documentation/en-us/uefn/run-your-first-verse-program-in-unreal-editor-for-fortnite
- /docs/documentation/en-us/uefn/modify-and-run-your-first-verse-program-in-unreal-editor-for-fortnite

---

## Lesson 3: Variables and Data Types in Verse

**Objectives:**

- Explain what a variable is and why programs need them
- Identify the three main data types in Verse: int, float, and string
- Declare and update variables inside a real Verse device script
- Connect variable changes to visible gameplay events on a Fortnite island

### 🎮 What Is a Variable?

Imagine you have a **scoreboard** in your Fortnite island. Every time a player scores a point, the number goes UP. That number is not stuck at one value — it **changes**. In Verse, we use a **variable** to hold a value that can change during the game.

Think of a variable like a **labeled box**:
- The **label** is the name you give it (like `Score`).
- The **stuff inside** is the value (like `0`, then `1`, then `2`…).
- You can swap what's inside the box anytime!

> 🧠 **Variable** = a named box that stores one piece of information, and that information can change while the game is running.

---

### 📦 Constants — The Box That Never Opens Again

Sometimes you want a value that **never** changes. Like the number of lives players start with — it's always 3. We call that a **constant**.

> 🧠 **Constant** = a named box that is sealed shut. You set it once and it stays that way forever.

In Verse, you write a constant with `:=` and you **never** change it after that first line.

---

### 🗂️ Data Types — What Kind of Stuff Is in the Box?

Not all boxes hold the same kind of stuff. In Verse, every variable has a **data type** — that just means "what kind of information is stored here?"

Here are the three main types you'll use:

| Data Type | What It Holds | Real-Life Example |
|-----------|--------------|-------------------|
| **int** | Whole numbers (no decimals) | Score: `0`, `5`, `100` |
| **float** | Numbers with decimals | Speed: `1.5`, `9.8` |
| **string** | Words or text | Player name: `"Hero"` |

- **int** is short for *integer* — a fancy word for a whole number like `3` or `42`.
- **float** is a number with a decimal point, like `3.14` or `0.5`.
- **string** is text wrapped in quotes, like `"Game Over"` or `"Player 1"`.

> 🎯 **Game tip:** Your player's score is an `int`. A timer that counts down by half-seconds uses a `float`. A welcome message on screen is a `string`!

---

### ✍️ How to Write Variables in Verse

Here is the recipe for making a variable in Verse:

```
Name : type = StartingValue
```

For a variable that can **change**, you add the word `var` in front:

```
var Name : type = StartingValue
```

The `:=` symbol means "set this right now." You'll use it to **change** a `var` later in your code.

Let's look at real examples:

```verse
var Score : int = 0        # A whole-number box that starts at zero
var TimerSeconds : float = 30.0   # A decimal-number box starting at 30
var WelcomeMessage : string = "Welcome to my island!"  # A text box
```

Notice the `#` — anything after `#` is a **comment**. Comments are notes for YOU. The computer ignores them completely!

---

### 🔗 How This Connects to Your Island

In UEFN, you build a **Verse device** — think of it like a special prop that runs your code. When the game starts, your device wakes up and runs its `OnBegin` function. That's where your variables spring to life!

When a player steps on a trigger, your code can **change** the variable:
- `set Score = Score + 1` — adds 1 to the score box!

You can then use that score to do things like grant items or activate devices. Your variable is the brain keeping track of everything. 🧠

### Worked Example

### 🏗️ Building a Score Tracker Device

**The scenario:** A player steps on a trigger pad. Each time they do, their score goes up by 1. When the score hits 3, a message prints — they WIN! We'll use a `trigger_device` in UEFN and write a Verse script to track the score.

**Step 1:** In UEFN, create a new Verse device file. Here's the complete script:

```verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /EpicGames.com/Temporary/Diagnostics }

# This is our custom device — it tracks a player's score
score_tracker_device := class(creative_device):

    # Hook up a Trigger Device in UEFN's detail panel
    @editable
    TriggerPad : trigger_device = trigger_device{}

    # A variable to hold the current score — starts at zero
    # 'var' means this value CAN change during the game
    var Score : int = 0

    # A constant — the score needed to win never changes
    WinScore : int = 3

    # OnBegin runs automatically when the game starts
    OnBegin<override>()<suspends> : void =
        # Tell the trigger to call our function each time it fires
        TriggerPad.TriggeredEvent.Subscribe(OnPlayerTriggered)

    # This function runs every time a player steps on the trigger
    OnPlayerTriggered(Agent : agent) : void =
        # Add 1 to the Score box
        set Score = Score + 1

        # Print the new score so we can see it in the log
        Print("Score is now: {Score}")

        # Check if the player has reached the winning score
        if (Score >= WinScore):
            Print("🎉 You Win! Great job!")
```

---

### 🔍 Walkthrough — Line by Line

| Line | What it does |
|------|-------------|
| `using { /Fortnite.com/Devices }` | Tells Verse we want to use Fortnite devices like triggers |
| `score_tracker_device := class(creative_device):` | Creates our custom device |
| `@editable` | Makes `TriggerPad` appear in the UEFN editor so you can drag-and-drop a trigger onto it |
| `var Score : int = 0` | Makes a changeable box called `Score` that holds whole numbers, starting at `0` |
| `WinScore : int = 3` | A **constant** — no `var`, so it can never be changed by accident |
| `OnBegin<override>()<suspends> : void =` | Runs once when the game starts |
| `TriggerPad.TriggeredEvent.Subscribe(OnPlayerTriggered)` | Listens for the trigger and calls our function when it fires |
| `set Score = Score + 1` | Opens the `Score` box and puts in the old value plus one |
| `Print("Score is now: {Score}")` | Shows the score in the Output Log — great for testing! |
| `if (Score >= WinScore):` | Checks if score is 3 or more |
| `Print("🎉 You Win!")` | Celebrates the win! |

> ✅ **Try it:** In UEFN, place a Trigger Device on your island. Assign it to `TriggerPad` in the device details. Hit **Launch Session** and walk over the trigger three times. Watch the Output Log — you should see the score climb to 3 and then see the win message!

### Try It Yourself

### 🛠️ Your Turn — Add a Lives Counter!

You just made a score tracker. Now let's add a **lives system**!

**Your challenge:**

1. Add a new `var` variable called `Lives` of type `int`. Start it at **3**.
2. Add a **second** `@editable` trigger called `DangerZone` of type `trigger_device`.
3. Subscribe to `DangerZone.TriggeredEvent` with a new function called `OnDangerTriggered`.
4. Inside `OnDangerTriggered`, **subtract 1** from `Lives` using `set Lives = Lives - 1`.
5. Print the new lives count with `Print("Lives left: {Lives}")`.
6. Add an `if` check — if `Lives <= 0`, print `"💀 Game Over!"`.

**In UEFN:** Place a second Trigger Device somewhere dangerous on your island (like lava or a trap area). Assign it to `DangerZone`. Play the island and walk into the danger zone three times!

---

> 💡 **Hint:** Subtracting in Verse looks just like adding, but with a `-` sign instead of `+`. The `if` check for lives running out looks just like the win check in the example — just change the variable name and the message!

> 🌟 **Bonus challenge:** Can you add a `string` variable called `PlayerStatus` that starts as `"Alive"` and changes to `"Defeated"` when lives hit zero?

### Quiz

1. What is a variable in Verse?
   - A. A value that is set once and never changes
   - B. A named box that stores information which can change during the game
   - C. A special Fortnite device you place on your island
   - D. A comment that the computer ignores

2. A player's score in a game is 10. What is the best data type to store it?
   - A. string, because scores are important words
   - B. float, because all numbers need decimals
   - C. int, because a score is a whole number with no decimal
   - D. var, because it can change

3. Which line of Verse code correctly creates a variable for a player's speed that starts at 5.5?
   - A. Speed : int = 5.5
   - B. var Speed : float = 5.5
   - C. var Speed : string = 5.5
   - D. Speed : var = 5.5

4. In the score tracker example, why is WinScore written WITHOUT the word var?
   - A. It was a mistake — all variables need var
   - B. Because int variables never need var
   - C. Because WinScore is a constant — the winning number never changes during the game
   - D. Because string types don't use var

**Answer key:**

1. B — A variable is like a labeled box — you can change what's inside it while the game is running. That's what makes it different from a constant!
2. C — A score like 10 is a whole number — no decimal needed! That makes int the perfect type. (var just means it CAN change — it's not a data type by itself.)
3. B — 5.5 has a decimal, so the type should be float. We need var because speed can change during the game. The correct recipe is: var Name : type = value.
4. C — WinScore is a constant — the score you need to win stays the same the whole game. Leaving out var means Verse won't let you accidentally change it later. Smart move!

### Recap

### 🌟 Great Work — Here's What You Learned!

A **variable** is a named box that stores information that can change during your game — like a score that goes up when a player does something. A **constant** is a sealed box set once and never changed. Every variable has a **data type**: **int** for whole numbers, **float** for decimal numbers, and **string** for text. You used all of these inside a real Verse device that tracked a player's score on a Fortnite island — and that's genuinely awesome programming! 🎉

**Sources:**

- /docs/documentation/en-us/fortnite/basics-of-writing-code-1-basic-programming-terms-in-verse
- /docs/documentation/en-us/uefn/learn-the-basics-of-writing-code-in-verse
- /docs/documentation/en-us/fortnite/learn-the-basics-of-writing-code-in-verse

---

## Lesson 4: Writing and Using Functions

**Objectives:**

- Define your own function in Verse using a name, parameters, and a return type.
- Call (use) a function you wrote to run its code from another place.
- Use a function with a parameter to give it different information each time you call it.
- Connect a custom function to a real Fortnite island moment, like a player stepping on a trigger.

### 🎮 Why Do We Need Functions?

Imagine you're building a Fortnite island. Every time a player steps on a pressure plate, you want to:
1. Add 10 points to their score.
2. Play a sound.
3. Print a message.

What if there are **20** pressure plates? You'd have to write those same 3 steps **20 times**. That's exhausting! 😩

A **function** fixes this. Think of a function like a **vending machine**. You press a button (call the function), and the machine does all the work for you every time. You only have to *set it up once*.

---

### 🧩 What Is a Function?

A **function** is a named block of code that does one job. You write it once, then **call** it (run it) as many times as you want.

Think of it like a recipe card. The card says "make a sandwich." You follow the steps. Next time you're hungry, you grab the *same card* — you don't write a new recipe!

---

### 📦 What Is a Parameter?

A **parameter** is information you hand to a function so it can do its job. It's like telling the vending machine *which snack* you want. Different input → different result!

For example, imagine a function called `GivePoints`. You could tell it to give **10** points one time, and **50** points another time. Same function, different number!

In Verse, you write a parameter like this inside the parentheses `()`:

```
Points : int
```

- `Points` is the **name** we give the information.
- `int` means it's a **whole number** (like 5, 10, or 100). "int" is short for *integer*, which just means a number without a decimal.

---

### 🎁 What Is a Return Value?

Sometimes you want a function to **give something back** after it runs. That's called a **return value**.

Imagine you ask a friend, "How many lives do I have left?" Your friend counts and *tells you back* the answer. That answer is the return value!

In Verse, you write `: int` (or another type) after the parentheses to say "this function will hand back a number."

If a function doesn't need to give anything back, you just leave that part out (or use `: void`).

---

### 🛠️ The Parts of a Function in Verse

Here's what a function looks like, piece by piece:

```
FunctionName(ParameterName : type) : returnType =
    # Your code goes here, indented
```

- **FunctionName** — what you call the function (like `GivePoints`).
- **(ParameterName : type)** — the info you hand in.
- **: returnType** — what type of thing the function gives back.
- **=** — this is like saying "here comes the recipe!"
- The indented lines below are the actual steps.

---

### 📣 Calling a Function

**Calling** a function means telling it to run. You just write its name and pass in any info it needs:

```
GivePoints(10)
```

That's it! The vending machine does its job. 🎉

---

### 🏝️ Connecting to Your Island

In UEFN, your Verse code lives inside a **Verse Device** — a special invisible gadget you place on your island. When something happens in the game (like a player steps on a **Trigger** device), your device can run a function.

Here's the big picture of how it works:

1. You place a **Trigger** device on your island in UEFN.
2. Your Verse device has a reference to that trigger.
3. When the trigger fires, Verse calls your function automatically.
4. Your function runs its steps — like printing a score message!

This is the magic of functions: the island event calls your function, and your function does all the hard work! 🚀

### Worked Example

### 🔨 Worked Example: A Score Announcer Device

**The scenario:** A player walks into a trigger zone on your island. Your Verse device runs a function that calculates their *bonus score* and prints a hype message. Let's build it!

---

**Step 1 — Set up in UEFN:**
- In UEFN, go to **Verse > Verse Explorer**, right-click your project, and choose **Add new Verse file to project**.
- Pick **Verse Device** as the template. Name it `score_announcer`.
- Drag a **Trigger** device onto your island.
- Compile (**Verse > Build Verse Code**), then drag your new device into the level too.

---

**Step 2 — The Verse code:**

```verse
using { /Script/VerseRuntime }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }

# This is our Verse Device class.
score_announcer := class(creative_device):

    # We hook up a Trigger device here in the UEFN editor.
    @editable
    MyTrigger : trigger_device = trigger_device{}

    # OnBegin runs automatically when the game starts.
    OnBegin<override>()<suspends> : void =
        # Tell the trigger: when someone enters it, call OnPlayerTriggered.
        MyTrigger.TriggeredEvent.Subscribe(OnPlayerTriggered)

    # This function runs when the trigger fires.
    # Agent is the player who stepped on the trigger.
    OnPlayerTriggered(Agent : agent) : void =
        # Calculate the bonus using our helper function.
        Bonus := CalculateBonus(10)
        # Print the result so we can see it while playtesting.
        Print("Bonus points earned: {Bonus}")

    # ------------------------------------------
    # Our custom function!
    # It takes one parameter: BasePoints (a whole number).
    # It returns a whole number (the bonus score).
    # ------------------------------------------
    CalculateBonus(BasePoints : int) : int =
        # Double the base points and give that back.
        return BasePoints * 2
```

---

### 📖 Walkthrough — What Each Part Does

| Line / Block | Plain-English Meaning |
|---|---|
| `score_announcer := class(creative_device)` | Creates our custom device. Think of it as naming our vending machine. |
| `@editable` / `MyTrigger` | Lets us plug in a real Trigger device from the UEFN editor — like connecting a wire. |
| `OnBegin<override>()<suspends> : void` | This special function runs the moment the game starts. `void` means it gives nothing back. |
| `MyTrigger.TriggeredEvent.Subscribe(OnPlayerTriggered)` | "Hey Trigger, when you fire, call `OnPlayerTriggered`!" Like setting up a doorbell. |
| `OnPlayerTriggered(Agent : agent) : void` | Runs when a player steps on the trigger. `Agent` is that player. |
| `CalculateBonus(10)` | **Calling** our custom function and handing it the number 10. |
| `CalculateBonus(BasePoints : int) : int` | **Defining** our custom function. It takes a number in and gives a number back. |
| `return BasePoints * 2` | Doubles the number and hands it back to whoever called the function. |

---

### 🎮 Try It!

1. Compile and drag both devices onto your island.
2. In the UEFN editor, click your `score_announcer` device and set `MyTrigger` to point at your Trigger device.
3. Hit **Launch Session** and walk into the trigger zone.
4. Look at the on-screen log — you should see **"Bonus points earned: 20"**!

You just wrote and called your very own function. You're a real programmer now! 🏆

### Try It Yourself

### 🕹️ Your Turn: The Multiplier Machine

You did awesome with `CalculateBonus`! Now it's time to level up. 💪

**Your challenge:**

Add a **second custom function** called `CalculateTripleBonus` to the `score_announcer` device. This function should:

1. Take one parameter: a whole number called `BasePoints`.
2. **Multiply** `BasePoints` by **3** (triple it!).
3. **Return** the result.

Then, inside `OnPlayerTriggered`, call your new function with the number **15** and print the result like this:

```
Triple bonus: 45
```

---

**🪜 Hints (if you need them!):**

- Your new function will look very similar to `CalculateBonus`. You can use it as a starting point!
- To multiply in Verse, use the `*` symbol. So `15 * 3` gives you `45`.
- To call your function and save the result, use:
  ```verse
  TripleResult := CalculateTripleBonus(15)
  ```
- To print it, use:
  ```verse
  Print("Triple bonus: {TripleResult}")
  ```

**Bonus challenge 🌟:** Can you call `CalculateBonus` AND `CalculateTripleBonus` in the same `OnPlayerTriggered` function and print both results?

Go for it — you've totally got this! 🎉

### Quiz

1. What is a function in programming?
   - A. A type of Fortnite weapon.
   - B. A named block of code that does one job and can be run many times.
   - C. A variable that stores a player's score.
   - D. A device you place on your island.

2. What is a parameter?
   - A. The name of a Verse device.
   - B. A special button in UEFN.
   - C. Information you hand into a function so it can do its job.
   - D. The return value of a function.

3. Look at this code: CalculateBonus(BasePoints : int) : int. What does the SECOND `: int` mean?
   - A. The function needs two numbers.
   - B. The function will give back a whole number when it's done.
   - C. The parameter must be named 'int'.
   - D. The function runs twice.

4. You wrote a function called GiveShield. How do you call it and hand it the number 50?
   - A. function GiveShield(50)
   - B. GiveShield : 50
   - C. GiveShield(50)
   - D. call GiveShield with 50

**Answer key:**

1. B — A function is like a recipe — you write it once and can "use" it (call it) as many times as you need. It's a named block of code that does one job!
2. C — A parameter is like telling the vending machine which snack you want. It's the information you give a function so it knows what to work with.
3. B — The return type (the second ': int') tells Verse what kind of thing the function will hand back. Here it means the function gives back a whole number (int).
4. C — In Verse, you call a function by writing its name followed by parentheses with the value inside — just like GiveShield(50). Simple and clean!

### Recap

### 🌟 Great Work — Here's What You Learned!

A **function** is a named block of code you write once and can run (call) as many times as you need — like a vending machine you set up once. You can hand a function information using **parameters**, and a function can **return** (give back) a result when it's done. In your Fortnite island, functions connect to real game moments — like a player stepping on a trigger — so your island actually *does something* when players play it. Keep building, keep creating, you're doing amazing! 🚀

**Sources:**

- /docs/documentation/en-us/uefn/learn-the-basics-of-writing-code-in-verse
- /docs/documentation/en-us/uefn/create-your-own-device-in-verse
- /docs/documentation/en-us/fortnite/create-your-own-device-in-verse

---

## Lesson 5: Control Flow: If Statements and Loops

**Objectives:**

- Write an if/else statement in Verse that checks a player's score and triggers a game event
- Use a loop in Verse to repeat an action a set number of times on your island
- Explain in your own words what 'control flow' means using a real game example
- Connect if statements and loops to real Fortnite island devices like Item Granters and Score Managers

### 🎮 What Is Control Flow?

Imagine you are playing a board game. You roll the dice. **If** you land on a red square, you lose a turn. **Otherwise**, you move ahead. The rules of the board game *control* what happens next.

In coding, **control flow** means: *the order in which your code runs, and which parts it chooses to run.* You are the rule-maker. You tell the computer, "Do THIS if something is true. Do THAT if it isn't."

---

### 🚦 If Statements — Your Game's Referee

An **if statement** is like a referee on your island. It watches what is happening. Then it makes a call.

Think of it like this:

> **If** the player's score is 10 or more → open the treasure chest!
> **Else** → keep the chest locked.

The word **if** starts the check. The word **else** handles everything that is NOT true.

In Verse, it looks like this:

```verse
if (Score >= 10):
    # Do this when score is high enough
else:
    # Do this when score is too low
```

- The stuff inside the **if** only runs when the condition is **true**.
- The stuff inside the **else** runs when the condition is **false**.
- Think of the condition like a yes/no question: "Is the score 10 or more?" Yes or no?

> 💡 **New Word — Condition:** A condition is a question that is either TRUE or FALSE. "Is it raining?" is a condition. "Is the player's score above 5?" is also a condition!

---

### 🔁 Loops — Your Island's Copy Machine

What if you wanted to give every player on your island 3 potions, one at a time? You could write the same line of code 3 times. But what if you wanted to do it 100 times? Writing 100 lines is no fun!

A **loop** is like a copy machine for your code. It runs the same instructions over and over until you say stop.

> 💡 **New Word — Loop:** A loop repeats a block of code. It's like pressing "replay" on a song, but for instructions.

Verse has a simple counting loop called a **for loop**. You tell it how many times to repeat. Here is the idea:

```verse
for (Index := 0..2):
    # This runs 3 times (0, 1, 2)
```

That `0..2` means "count from 0 up to and including 2." That is 3 counts total. Think of it as laps around a track: lap 0, lap 1, lap 2 — done!

> 🏃 **Analogy:** A for loop is like a coach yelling "Run 3 laps!" Your player runs one lap, then another, then another — and stops.

---

### 🧩 Putting It Together on Your Island

Let's say you are building a **Score Challenge** island. Here is the plan:

- A player steps on a **Trigger** device.
- Your Verse code checks: **Did the player reach 5 points?**
- **If yes** → an **Item Granter** gives them a Legendary weapon. 🎉
- **If no** → nothing special happens yet.
- Also, when the game starts, a loop **grants 3 common weapons** to warm up the player.

You use an **if statement** for the score check. You use a **loop** for the weapon hand-out. Together, they make your island smart and fun!

---

### 🗂️ The Shape of Verse Code

Two things to always remember about Verse:

1. **Indentation matters.** The code *inside* an if statement or loop must be indented (pushed in with spaces). This is how Verse knows which lines belong together.
2. **Colons start a block.** After `if(...)` and `for(...)`, you put a colon `:` and then indent the next lines.

Think of indentation like putting toys inside a box. The toys (code lines) belong to the box (if or loop) only if they are *inside* it.

### Worked Example

### 🏗️ Building a Score Reward System

**The island plan:**
- Drop a **Trigger Device** in your UEFN island.
- Drop an **Item Granter Device** and set it to grant a Legendary item.
- Drop a **Score Manager Device**.
- Attach this Verse script to a **Verse Device** in your island.

When a player walks into the trigger, the code checks their score. If they earned 5 or more points, the Item Granter fires! The loop at the start hands out 3 starting items automatically.

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

# This is our Verse device class — it lives on the island
score_reward_device := class(creative_device):

    # Plug these in from the UEFN editor by selecting your devices
    @editable
    GranterDevice : item_granter_device = item_granter_device{}

    @editable
    TriggerDevice : trigger_device = trigger_device{}

    # OnBegin runs once when the game starts
    OnBegin<override>()<suspends> : void =
        # Subscribe to the trigger — when a player steps on it, call OnTriggered
        TriggerDevice.TriggeredEvent.Subscribe(OnTriggered)

    # This function runs every time a player hits the trigger
    OnTriggered(Agent : agent) : void =
        # Try to get the player's score from the score manager
        # We track score with a simple variable here for the example
        var PlayerScore : int = 6  # Pretend the player has 6 points

        # ---- IF STATEMENT ----
        # Check: does the player have 5 or more points?
        if (PlayerScore >= 5):
            # YES — grant them a reward item!
            GranterDevice.GrantItem(Agent)
            Print("Great job! You earned a reward!")  # Shows in the log
        else:
            # NO — encourage them to keep going
            Print("Keep collecting points — you need 5!")
```

### 🔍 Walkthrough — Line by Line

| Code Part | What It Does |
|---|---|
| `score_reward_device := class(creative_device)` | Creates our island device — like building a new LEGO piece |
| `@editable` | Lets us plug in real devices from the UEFN editor |
| `OnBegin<override>()<suspends> : void` | Runs once when the game starts |
| `TriggerDevice.TriggeredEvent.Subscribe(OnTriggered)` | Tells the trigger: "Call OnTriggered when someone steps on you" |
| `var PlayerScore : int = 6` | A variable storing the player's score (6 for this example) |
| `if (PlayerScore >= 5):` | The BIG QUESTION — is the score 5 or more? |
| `GranterDevice.GrantItem(Agent)` | Gives the item to the player who triggered it |
| `else:` | Handles the "not enough points" case |
| `Print(...)` | Sends a message to the output log so you can see what happened |

> ✅ **Try it!** In UEFN, place a Trigger Device and an Item Granter Device. Connect them to your Verse device using the `@editable` slots. Change `PlayerScore` to 3 and play — you should see the "keep collecting" message instead!

---

### 🔁 Bonus: Adding a Loop for Warm-Up Items

Want to grant 3 items when the game starts? Add this loop inside `OnBegin`, **before** the Subscribe line:

```verse
# Loop 3 times (Index goes 0, 1, 2)
for (Index := 0..2):
    # Each loop gives ALL agents a starting item
    # (In a real game, you'd loop through players — this shows the loop shape)
    Print("Granting warm-up item number {Index}")
    # GranterDevice.GrantItem(SomeAgent)  # Uncomment when you have a real agent
```

> 🎉 **What just happened?** The loop ran 3 times on its own. You wrote the `Print` line once but the computer did it 3 times. That's the magic of loops!

### Try It Yourself

### 🛠️ Your Turn: The Double Score Challenge!

You are going to upgrade the Score Reward System. Here is your challenge:

**Goal:** Change the if statement so there are THREE outcomes instead of two:
1. If the player's score is **10 or more** → print `"LEGENDARY reward unlocked!"`
2. If the player's score is **5 or more (but less than 10)** → print `"Nice! Here's a common item!"`
3. If the score is **below 5** → print `"Keep going, you can do it!"`

In Verse, you can chain conditions like this using `else if`:

```verse
if (Score >= 10):
    # first case
else if (Score >= 5):
    # second case
else:
    # third case
```

**Steps:**
1. Open your Verse file from the worked example above.
2. Change `var PlayerScore : int = 6` to different values (like `11`, `7`, and `3`) to test each branch.
3. Update the if/else block to have all three cases using `else if`.
4. **Bonus 🌟:** Add a loop that counts from `1` to `5` and prints `"Counting: {Index}"` each time. Put it inside `OnBegin`.

> 💡 **Hint:** Remember to indent your code inside each `if`, `else if`, and `else` block. Verse is strict about indentation — it's like making sure your toys are *inside* the box, not next to it!

> 💪 **You've got this!** Try changing the score value and see how different branches run. That's real debugging — just like a game developer does!

### Quiz

1. What does an if statement do in Verse?
   - A. It runs the same code over and over forever
   - B. It checks a true/false condition and runs different code based on the answer
   - C. It stores a number like a player's score
   - D. It creates a new device on the island

2. In this Verse code: `for (Index := 0..2):` — how many times does the loop run?
   - A. 2 times
   - B. 0 times
   - C. 3 times
   - D. 4 times

3. What happens to the code inside an `else` block?
   - A. It always runs no matter what
   - B. It runs only when the if condition is TRUE
   - C. It runs only when the if condition is FALSE
   - D. It runs before the if statement checks anything

4. Why does indentation matter so much in Verse?
   - A. It makes the code look pretty but doesn't change how it works
   - B. It tells Verse which lines of code belong inside an if statement or loop
   - C. It makes the game run faster
   - D. It is only needed for Print statements

**Answer key:**

1. B — An if statement checks a condition — a yes or no question — and runs different code depending on whether the answer is true or false. It's like a referee making a call!
2. C — The range 0..2 counts 0, 1, and 2 — that's 3 numbers, so the loop runs 3 times. Think of it like 3 laps around a track!
3. C — The else block is the backup plan — it only runs when the if condition is false. Like: IF it's raining, grab an umbrella. ELSE, wear sunglasses!
4. B — In Verse, indentation tells the computer which lines belong inside a block of code (like an if or a loop). If your indentation is wrong, the code won't work right — just like toys falling out of a box if you don't put them inside it!

### Recap

### 🌟 Great Work — Here's What You Learned!

**Control flow** means deciding which code runs and when — just like the rules of a board game. An **if statement** checks a true/false condition and picks a path, like a referee making a call on your island. A **loop** repeats code automatically so you don't have to write the same lines over and over. Put them together and your Fortnite island can react to players, check scores, and hand out rewards like a real game designer made it! 🎮

**Sources:**

- /docs/documentation/en-us/uefn/learn-the-basics-of-writing-code-in-verse
- /docs/documentation/en-us/fortnite/learn-the-basics-of-writing-code-in-verse

---

## Lesson 6: Create Your First Verse Device Script

**Objectives:**

- Create a new Verse device file in UEFN using Verse Explorer.
- Write a Verse device script that uses a variable, a function, and an if/else check.
- Compile and drag your custom device into your Fortnite island level.
- Playtest your island and see your Verse code run live in the game.

### 🎮 What Is a Verse Device?

Imagine a **remote control car**. The car itself sits on the floor of your room — that's like your Fortnite island. The circuit board inside the car is the **device**. The instructions you program into it tell the car what to do: go forward, turn left, honk!

A **Verse device** works the same way. It's a little invisible gadget you place on your island. Your Verse code is the instructions inside it. When the game starts, the device follows your instructions and makes things happen!

---

### 🛠️ Step 1 — Create a New Verse Device File

First, you need to make the file where you'll write your code. Think of this like getting a blank piece of paper before you draw.

Here's how:

1. Open your project in **UEFN** (Unreal Editor for Fortnite).
2. In the top menu bar, click **Verse**, then click **Verse Explorer**. This is like a file cabinet for all your Verse scripts.
3. In Verse Explorer, **right-click** your project name. Choose **Add new Verse file to project**.
4. A window pops up. Click **Verse Device** as your template. A **template** is a starter design — like a cookie cutter that already has the basic shape.
5. In the **Device Name** box, type `score_tracker_device`. Then click **Create**.
6. Double-click your new file in Verse Explorer. It opens in **Visual Studio Code** — that's your coding notebook!

---

### 🧱 Step 2 — Understand the Starter Code

When UEFN creates your device file, it gives you some starter code. Here's what the important parts mean:

- **`using { /Script/FortniteGame }`** — This line is like saying "borrow tools from Fortnite's toolbox."
- **`creative_device`** — This is the special Verse type that makes your script become a real device on your island.
- **`OnBegin`** — This is a built-in function. It runs your code the moment the game starts. Think of it like the starting pistol at a race — *bang*, your code goes!

---

### 🔢 Step 3 — Variables: Boxes That Hold Information

A **variable** is like a labeled box. You put something inside, and you can change what's in it later.

For example:
- A box labeled `PlayerScore` might hold the number `0` at the start.
- When a player does something cool, you change it to `1`, then `2`, and so on!

In Verse, you create a variable like this:

```verse
var Score : int = 0
```

- `var` means "this box can change later."
- `Score` is the label on the box.
- `int` means the box holds a **whole number** (like 0, 1, 5 — no fractions).
- `= 0` is the starting value — the number already inside the box.

---

### ⚙️ Step 4 — Functions: Named Sets of Instructions

A **function** is like a recipe. You write it once, give it a name, and you can use it over and over.

Imagine a recipe called "Make Lemonade." Every time you follow it, you get lemonade! A function called `AddPoint` could say: every time you run it, add 1 to the score.

---

### 🔀 Step 5 — Control Flow: Making Decisions

**Control flow** means your code can make choices. Think of it like a Choose-Your-Own-Adventure book.

**If** something is true, do this. **Else** (otherwise), do that.

```verse
if (Score >= 3):
    Print("You win! 🎉")
else:
    Print("Keep going!")
```

- `if` asks a question: Is Score 3 or more?
- If YES, it prints "You win!"
- If NO, it prints "Keep going!"

---

### 📦 Step 6 — Compile and Place Your Device

**Compiling** means turning your human-readable code into something UEFN can actually run. It's like a translator turning English into Robot Language.

1. In the top menu, click **Verse > Build Verse Code**.
2. Wait a moment. Your device now appears in the **Content Browser** under **CreativeDevices**.
3. **Drag and drop** your device onto your island — just like placing any other object!
4. Click **Launch Session** in the toolbar to playtest. Hit **Start Game** and watch your code run! 🚀

### Worked Example

### 🏆 Worked Example: A Score-Tracking Device

**The goal:** Make a device that tracks a player's score. When the game starts, it gives the player points one at a time and announces when they win.

Place this code inside your device file in Visual Studio Code:

```verse
using { /Verse.org/Simulation }
using { /Verse.org/Native }
using { /UnrealEngine.com/Temporary/Diagnostics }

# This tells UEFN that our script is a real device for the island
score_tracker_device := class(creative_device):

    # A variable — like a labeled box — to hold the score.
    # "var" means we can change it later. It starts at 0.
    var Score : int = 0

    # OnBegin runs automatically the moment the game starts.
    # Think of it as the starting pistol for your code!
    OnBegin<override>()<suspends> : void =
        Print("Game started! Score = 0")  # Announce the start

        # Call our custom function to add a point
        AddPoint()
        AddPoint()
        AddPoint()  # Add three points, one at a time

    # This is our custom function — a recipe called "AddPoint"
    AddPoint() : void =
        set Score = Score + 1  # Open the box, add 1, put it back
        Print("Score is now: {Score}")  # Show the new score

        # Control flow: check if the player has won yet
        if (Score >= 3):
            Print("YOU WIN! Amazing job! 🎉")  # Score is 3 or more
        else:
            Print("Keep it up! Almost there!")  # Score is less than 3
```

### 📖 Walkthrough

| Line | What it does |
|------|-------------|
| `score_tracker_device := class(creative_device)` | Says "this is a device that goes on the island" |
| `var Score : int = 0` | Creates a number box called Score, starting at 0 |
| `OnBegin<override>()<suspends> : void =` | This runs the moment the game starts |
| `AddPoint()` | Runs our recipe/function to add one point |
| `set Score = Score + 1` | Opens the Score box and adds 1 |
| `if (Score >= 3)` | Asks: is Score 3 or bigger? |
| `Print(...)` | Shows a message in the game log — great for testing! |

### 🎮 What You'll See

When you playtest, check the **Output Log** in UEFN. You'll see messages like:
```
Game started! Score = 0
Score is now: 1
Keep it up! Almost there!
Score is now: 2
Keep it up! Almost there!
Score is now: 3
YOU WIN! Amazing job! 🎉
```

Your Verse code is running live inside your Fortnite island! How cool is that? 🌟

### Try It Yourself

### 🎯 Your Turn: Build a Countdown Device!

You just saw a score go **up**. Now try making it go **down** — like a countdown!

**Your mission:**
1. Create a **new** Verse device called `countdown_device`.
2. Add a variable called `TimeLeft` that starts at `5`.
3. Write a function called `Tick` that **subtracts 1** from `TimeLeft` each time it runs. *(Hint: subtraction uses the `-` symbol!)*
4. Call `Tick` five times inside `OnBegin`.
5. Use an `if/else` to check: if `TimeLeft <= 0`, print `"Blast off! 🚀"`. Otherwise, print `"Counting down: {TimeLeft}"`.
6. Compile your code (**Verse > Build Verse Code**), drag it onto your island, and playtest!

**🔑 Hints:**
- To subtract, use: `set TimeLeft = TimeLeft - 1`
- The structure of your function will look very similar to `AddPoint()` — just change `+` to `-` and update the variable name and messages!
- Remember: compile first, THEN drag it to the level!

**Bonus challenge 🌟:** Can you change the win condition so it prints a special message when `TimeLeft` reaches exactly `0`?

### Quiz

1. What does 'compiling' your Verse code do?
   - A. It deletes your code so you can start over.
   - B. It turns your code into something UEFN can actually run on your island.
   - C. It automatically adds your device to the level for you.
   - D. It sends your island to all your friends.

2. In Verse, what does the keyword 'var' tell the computer?
   - A. This value is a secret and will never be shown.
   - B. This is a function that runs automatically.
   - C. This is a box that can hold a value AND that value can change later.
   - D. This line of code should be skipped.

3. When does the 'OnBegin' function run in a Verse device?
   - A. Every single second while the game is running.
   - B. Only when a player walks into a trigger zone.
   - C. Automatically the moment the game starts.
   - D. Only when you manually call it from Verse Explorer.

4. What happens in Verse when an 'if' condition is FALSE?
   - A. The whole program stops and crashes.
   - B. The 'if' block is skipped, and the 'else' block runs instead.
   - C. The 'if' block runs twice to make up for it.
   - D. Verse ignores both the 'if' and 'else' blocks.

**Answer key:**

1. B — Compiling is like a translator. It takes the code you wrote and turns it into instructions the game engine can understand and run. You must compile before you can use your device on your island!
2. C — 'var' stands for variable — think of it as a labeled box. The 'var' keyword tells Verse that the value inside this box is allowed to change during the game, like a score that goes up each time a player scores a point.
3. C — OnBegin is like the starting pistol at a race — BANG, the game begins, and OnBegin fires immediately! It's the perfect place to set things up at the very start of your island game.
4. B — Control flow is like a fork in the road. If the condition is true, you go left (the 'if' block). If it's false, you go right (the 'else' block). One path always runs — they just take turns depending on the answer!

### Recap

### 🌟 Great Work — Here's What You Learned!

Today you built your very first custom Verse device from scratch. You learned that a **variable** is like a labeled box that can hold changing information (like a score), and a **function** is a reusable recipe of instructions you can call by name. You used **control flow** (if/else) to make your device make smart decisions. Finally, you compiled your code and dropped your device onto your real Fortnite island — which means YOU just made something that runs live inside a game. That is seriously impressive! 🎉

**Sources:**

- /docs/documentation/en-us/uefn/create-your-own-device-in-verse
- /docs/documentation/en-us/fortnite/create-your-own-device-in-verse
- /docs/documentation/en-us/fortnite/create-your-own-device-using-verse-in-unreal-editor-for-fortnite

---

*Generated by Verse Cortex on 2026-06-21.*
