Verse is a programming language that works with UEFN. This page covers the basics for quickly adding Verse into your projects, providing a foundation for programmers both new and experienced to get a feel for what can be done with the language.
The target devices you created earlier in this tutorial cannot be knocked down with a single hit, so you're going to learn how to use Verse to make them do exactly that!
Create a New Verse Device
You're going to create a Verse device and place it on your island.
Think of this as a device that will tell other devices what to do based on your instructions. Another way of putting it is that you're going to make a Verse program that reprograms an existing device in UEFN!
On the menu bar, select Verse > Verse Explorer.
In the Verse Explorer, right-click on your project and select Add new Verse file to project.
This opens the Create Verse Script window.
In the Create Verse Script window, select the Verse Device template.
Rename the device as shooting_range_manager_device at the bottom of the window, then click Create.
You will find the shooting_range_manager_device in the Content Browser under the project name, or use the search box to find the device.
On the menu bar, select Verse > Build Verse Code.
When working with code for a Verse device, you have to build (also called compiling) the device before you can use it. This means letting Verse put it into a format that you can run as a game or a part of a game. The Verse device will not show up in your Content Browser or the Outliner until it has been built.
You will find the shooting_range_manager_device in the Content Browser under the project name, or use the search box to find the device.
Drag the device into the viewport.
In the Details panel under User Options, uncheck Visible in Game to hide the device while the game is running.
Set Up the Good Targets
Remember the good targets from 3. Build a Shooting Gallery?
You're going to set up the good targets using your Verse device so that they pop down on a single hit.
In the Verse Explorer, double-click the
shooting_range_manager_device.verseto open the Verse file.Delete all of the code in the file then copy the code below and paste it where the old code was.
Verseusing { /Fortnite.com/Devices } using { /Verse.org/Simulation } # A device that manages shooting range gameplay. shooting_range_manager_device := class(creative_device): @editable GoodTarget1:shooting_range_target_track_device = shooting_range_target_track_device{} @editableIn Verse, a variable is information in the program that can change while the program is running.
When a variable is editable, this means that the code is exposed in UEFN, which in turn means that it can be changed from within UEFN without needing to rebuild your Verse code every time.
The code you just added to the Verse device makes three variables (GoodTarget1, GoodTarget2, and GoodTarget3) that are of the type
shooting_range_track_device. These will represent the targets the player will score points by hitting. By making these@editable, you can now set their values in the Details panel however you like without having to keep changing your Verse code. This code will still need to be compiled, because it's the first time you're adding it.With the Details panel of your shooting_range_manager_device open, from the viewport, select the shooting_range_manager_device.
Compile your code.
In the Details panel, set the value for each good target to a different Target Dummy Track device.
Starting at
<# --- New Code Start --- #>in the code block below, copy and paste the following code into the Verse file. This snippet makes a good target pop down when hit.The event subscriptions link the target's
HitEventand the callback defined for that target.Verse<# --- New Code Start --- #> # Runs when the device is started in a running game. OnBegin<override>()<suspends>:void= # Subscribing to the GoodTarget HitEvents. GoodTarget1.HitEvent.Subscribe(OnGoodTarget1Hit) GoodTarget2.HitEvent.Subscribe(OnGoodTarget2Hit) GoodTarget3.HitEvent.Subscribe(OnGoodTarget3Hit) # A hit callback that pops down the first GoodTarget.Compile your code after pasting.
Whenever you see a line in a code block that starts with # or <# and ends with #>, these are called code comments.
Code Comments are not part of the program. They are comments written by the programmer to provide information to other programmers, or to remind themselves why they did something the way they did.
For more information about code comments, see the Code Comments section of the Verse Language Quick Reference.
Set Up the Bad Targets
Your bad targets are the Target Dummy devices, customized as Teddy Bears. This time, you'll add them to your Verse device so that they'll pop down with a single hit, but make it so that the player loses points with each hit instead of gaining points.
Add the following code to create three
shooting_range_target_devicevariables to store references to the bad targets.Verseusing { /Fortnite.com/Devices } using { /Verse.org/Simulation } # A device that manages shooting range gameplay. shooting_range_manager_device := class(creative_device): @editable GoodTarget1:shooting_range_target_track_device = shooting_range_target_track_device{} @editableCompile your code.
Select the shooting_range_manager_device in the viewport.
In the Details panel, set the value for each bad target to a different Target Dummy device.
Add the following code to pop down the bad targets when hit.
Verseusing { /Fortnite.com/Devices } using { /Verse.org/Simulation } # A device that manages shooting range gameplay. shooting_range_manager_device := class(creative_device): @editable GoodTarget1:shooting_range_target_track_device = shooting_range_target_track_device{} @editable
Set Up Scoring
Before you can use Verse to customize a device, you have to add the device you want to customize.
You can set up scoring using only Fortnite devices, but it is easier to do this in Verse, and you can do it with fewer devices.
Add a Scoring Device
Even though you will be setting up two types of scoring (adding points and subtracting points), by using Verse, you only need one scoring device to do it all.
From the Content Browser, type Score Manager in the search bar to find the Score Manager device.
Drag the Score Manager device into the viewport. The Score Manager user options should be open in the Details panel.
From the Details panel, modify the following options:
Option and Value Enable During Phase = Gameplay Only
Display Score Update on HUD = Check
Customize the Scoring Device with Verse
Now you can add the Score Manager to your Verse device and adjust the player's score based on the targets hit.
Add the following code to create variables for a storing reference to the score manager and score values. You can change default score values by changing the assigned values or override the default by changing the values in the Details panel.
Verseusing { /Fortnite.com/Devices } using { /Verse.org/Simulation } # A device that manages shooting range gameplay. shooting_range_manager_device := class(creative_device): <# --- New Code Start --- #> @editable ScoreManager:score_manager_device = score_manager_device{}Compile your code.
Select the shooting_range_manager_device in the viewport.
In the Details panel of the shooting_range_manager_device, set ScoreManager to the Score Manager device.
Add the following code to update the player's score when hitting good and bad targets.
Verseusing { /Fortnite.com/Devices } using { /Verse.org/Simulation } # A device that manages shooting range gameplay. shooting_range_manager_device := class(creative_device): @editable ScoreManager:score_manager_device = score_manager_device{} @editableCompile your code.
Select Verse > Build Verse Code from the Menu Bar.
If you keep your Fortnite session open, click Push Changes to the live edit so it receives the updates you made with Verse. You may also have to end and restart a game to see the changes come through properly.
Playtest your changes in your Fortnite session to make sure that:
Your score increases when hitting a good target. (Open the scoreboard while playing by pressing the M key.)
Your score decreases when you hit a bad target.
You can knock targets down with one hit.