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.
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!
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!
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:
Together they make a team. You build the island in UEFN, and Verse tells the island how to behave.
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:
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!
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! ๐ค
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! ๐")
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). OnBegin is 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!
Goal: Set up a UEFN project and get a Verse device running on your island.
Steps to follow:
my_first_device.๐ฏ 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!
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! ๐
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! ๐
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.
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.
Here's how to get started in UEFN:
๐ก Level means the map or island you are building. Dropping the device into it is like placing a LEGO brick on your baseplate.
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.
Now let's look at the code and change it!
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!| 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 |
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!
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.
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! ๐
You have seen how Print works. Now let's make the program say something new!
Your challenge:
OnBegin, add two new Print lines below the existing ones.
"My name is Alex!"){ } (example: "5 + 3 = {5 + 3}")๐ค Hints:
Print line goes inside OnBegin, with the same indentation (spacing) as the other Print lines."quotation marks".{ } inside the quotes โ like "10 - 4 = {10 - 4}".๐ 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!)
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! ๐
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:
Score).0, then 1, then 2โฆ).๐ง Variable = a named box that stores one piece of information, and that information can change while the game is running.
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.
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" |
3 or 42.3.14 or 0.5."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!
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!
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. ๐ง
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!")
| 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!
You just made a score tracker. Now let's add a lives system!
Your challenge:
var variable called Lives of type int. Start it at 3.@editable trigger called DangerZone of type trigger_device.DangerZone.TriggeredEvent with a new function called OnDangerTriggered.OnDangerTriggered, subtract 1 from Lives using set Lives = Lives - 1.Print("Lives left: {Lives}").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+. 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?
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! ๐
Imagine you're building a Fortnite island. Every time a player steps on a pressure plate, you want to:
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.
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!
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.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).
Here's what a function looks like, piece by piece:
FunctionName(ParameterName : type) : returnType =
# Your code goes here, indented
GivePoints).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. ๐
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:
This is the magic of functions: the island event calls your function, and your function does all the hard work! ๐
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:
score_announcer.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
| 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. |
score_announcer device and set MyTrigger to point at your Trigger device.You just wrote and called your very own function. You're a real programmer now! ๐
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:
BasePoints.BasePoints by 3 (triple it!).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!):
CalculateBonus. You can use it as a starting point!* symbol. So 15 * 3 gives you 45.TripleResult := CalculateTripleBonus(15)
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! ๐
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! ๐
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."
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
๐ก 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!
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.
Let's say you are building a Score Challenge island. Here is the plan:
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!
Two things to always remember about Verse:
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.
The island plan:
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
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:
"LEGENDARY reward unlocked!""Nice! Here's a common item!""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:
var PlayerScore : int = 6 to different values (like 11, 7, and 3) to test each branch.else if.1 to 5 and prints "Counting: {Index}" each time. Put it inside OnBegin.๐ก 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!
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! ๐ฎ
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!
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:
score_tracker_device. Then click Create.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!A variable is like a labeled box. You put something inside, and you can change what's in it later.
For example:
PlayerScore might hold the number 0 at the start.1, then 2, and so on!In Verse, you create a variable like this:
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.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.
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!")
if asks a question: Is Score 3 or more?Compiling means turning your human-readable code into something UEFN can actually run. It's like a translator turning English into Robot Language.
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
| 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! |
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? ๐
You just saw a score go up. Now try making it go down โ like a countdown!
Your mission:
countdown_device.TimeLeft that starts at 5.Tick that subtracts 1 from TimeLeft each time it runs. (Hint: subtraction uses the - symbol!)Tick five times inside OnBegin.if/else to check: if TimeLeft <= 0, print "Blast off! ๐". Otherwise, print "Counting down: {TimeLeft}".๐ Hints:
set TimeLeft = TimeLeft - 1AddPoint() โ just change + to - and update the variable name and messages!Bonus challenge ๐: Can you change the win condition so it prints a special message when TimeLeft reaches exactly 0?
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! ๐