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.
Learning Outcomes
- 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?
- 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!
# 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
-
using { /fortnite/devices }โ This line imports tools from Fortnite. It's like opening your toolbox before you start building. -
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." -
OnBegin<override>()<suspends>:void=โ This is a function (a named set of instructions).OnBeginis the name Verse uses for "run this when the game begins." -
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:
- Open UEFN and create a new project using a blank island template.
- In the top menu, go to Verse > Create New Verse File. Name it
my_first_device. - Look at the worked example above. Type the code into your new file. (Don't copy-paste โ typing it helps your brain learn it!)
- In UEFN, click Verse > Build Verse to check for errors.
- Drag your new device from the Content Browser onto the island floor.
- 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:
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
- 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
- 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
- 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
- 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
- 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!
- 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!
- 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!
- 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
Lesson 2: Run Your First Verse Program
- 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:
- Open UEFN. In the Project Browser, click Feature Examples.
- Find and click Verse Device template, then give your project the name MyVerseProject. Click Create.
- 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.
- Right-click your project name in Verse Explorer. Choose Add new Verse file to project.
- In the window that pops up, click Verse Device, then click Create. This creates a starter code file called hello_world_device.verse. ๐
- Go to Verse > Build Verse Code so UEFN notices your new file.
- 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
- Click Launch Session in the toolbar. A window may ask you to save โ click Save Selected.
- When it loads, open the Main Menu and click Start Game.
- Once in the game, press Escape, click Island Settings, then click Log at the top.
- 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!
- 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.
- You will see the starter code. We will look at it together in the next section.
- You can add a new
Printline 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 |
| 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:
# 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 toPrinttext. -
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 fromcreative_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.OnBeginis 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 calculates2 + 2and writes4for 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:
- Open hello_world_device.verse in VS Code.
- Inside
OnBegin, add two newPrintlines 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}")
- One line should print your name (example:
- Save your file in VS Code (press Ctrl+S on Windows or Cmd+S on Mac).
- In UEFN, go to Verse > Build Verse Code.
- Click Launch Session, start the game, and check the Log for your new messages!
๐ค Hints:
- Every
Printline goes insideOnBegin, 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
- 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.
- What is the name of the special function that runs automatically when your game starts?
- A. StartGame
- B. OnBegin
- C. LaunchSession
- D. Print
- 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"}
- 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.
- B โ In Verse, `Print` sends a text message to the Log โ a special screen that shows notes from your code. No paper involved! ๐
- 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!
- 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`!
- 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
Lesson 3: Variables and Data Types in Verse
- 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, then1, then2โฆ). - 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
3or42. - float is a number with a decimal point, like
3.14or0.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 afloat. A welcome message on screen is astring!
โ๏ธ 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:
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:
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
TriggerPadin 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:
- Add a new
varvariable calledLivesof typeint. Start it at 3. - Add a second
@editabletrigger calledDangerZoneof typetrigger_device. - Subscribe to
DangerZone.TriggeredEventwith a new function calledOnDangerTriggered. - Inside
OnDangerTriggered, subtract 1 fromLivesusingset Lives = Lives - 1. - Print the new lives count with
Print("Lives left: {Lives}"). - Add an
ifcheck โ ifLives <= 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+. Theifcheck 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
stringvariable calledPlayerStatusthat starts as"Alive"and changes to"Defeated"when lives hit zero?
Quiz
- 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
- 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
- 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
- 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
- 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!
- 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.)
- 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.
- 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
Lesson 4: Writing and Using Functions
- 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:
- Add 10 points to their score.
- Play a sound.
- 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
Pointsis the name we give the information.intmeans 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:
- You place a Trigger device on your island in UEFN.
- Your Verse device has a reference to that trigger.
- When the trigger fires, Verse calls your function automatically.
- 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:
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!
- Compile and drag both devices onto your island.
- In the UEFN editor, click your
score_announcerdevice and setMyTriggerto point at your Trigger device. - Hit Launch Session and walk into the trigger zone.
- 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:
- Take one parameter: a whole number called
BasePoints. - Multiply
BasePointsby 3 (triple it!). - 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. So15 * 3gives you45. - To call your function and save the result, use:
TripleResult := CalculateTripleBonus(15) - To print it, use:
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
- 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.
- 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.
- 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.
- 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
- 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!
- 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.
- 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).
- 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
Lesson 5: Control Flow: If Statements and Loops
- 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:
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:
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:
- 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.
- Colons start a block. After
if(...)andfor(...), 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.
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, ActualAgent := Agent?):
# YES โ grant them a reward item!
GranterDevice.GrantItem(ActualAgent)
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
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:
- If the player's score is 10 or more โ print
"LEGENDARY reward unlocked!" - If the player's score is 5 or more (but less than 10) โ print
"Nice! Here's a common item!" - If the score is below 5 โ print
"Keep going, you can do it!"
In Verse, you can chain conditions like this using else if:
if (Score >= 10):
# first case
else if (Score >= 5):
# second case
else:
# third case
Steps:
- Open your Verse file from the worked example above.
- Change
var PlayerScore : int = 6to different values (like11,7, and3) to test each branch. - Update the if/else block to have all three cases using
else if. - Bonus ๐: Add a loop that counts from
1to5and prints"Counting: {Index}"each time. Put it insideOnBegin.
๐ก Hint: Remember to indent your code inside each
if,else if, andelseblock. 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
- 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
- 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
- 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
- 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
- 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!
- 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!
- 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!
- 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
Lesson 6: Create Your First Verse Device Script
- 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:
- Open your project in UEFN (Unreal Editor for Fortnite).
- In the top menu bar, click Verse, then click Verse Explorer. This is like a file cabinet for all your Verse scripts.
- In Verse Explorer, right-click your project name. Choose Add new Verse file to project.
- 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.
- In the Device Name box, type
score_tracker_device. Then click Create. - 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
PlayerScoremight hold the number0at the start. - When a player does something cool, you change it to
1, then2, and so on!
In Verse, you create a variable like this:
var Score : int = 0
varmeans "this box can change later."Scoreis the label on the box.intmeans the box holds a whole number (like 0, 1, 5 โ no fractions).= 0is 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.
if (Score >= 3):
Print("You win! ๐")
else:
Print("Keep going!")
ifasks 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.
- In the top menu, click Verse > Build Verse Code.
- Wait a moment. Your device now appears in the Content Browser under CreativeDevices.
- Drag and drop your device onto your island โ just like placing any other object!
- 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:
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:
- Create a new Verse device called
countdown_device. - Add a variable called
TimeLeftthat starts at5. - Write a function called
Tickthat subtracts 1 fromTimeLefteach time it runs. (Hint: subtraction uses the-symbol!) - Call
Tickfive times insideOnBegin. - Use an
if/elseto check: ifTimeLeft <= 0, print"Blast off! ๐". Otherwise, print"Counting down: {TimeLeft}". - 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
- 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.
- 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.
- 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.
- 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.
- 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!
- 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.
- 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.
- 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! ๐