Build a Tower Defense Turret with Verse
Build a Tower Defense Turret with Verse
Welcome, future game creator! Do you want to build a fortress that fights back? Today, we will code a mounted turret. It shoots at enemies automatically. You do not need to aim. You just watch them go down. This is a classic tower defense move. We will use Verse to make it work. Let's get started!
What You'll Learn
- How to find the Mounted Turret device.
- What a Variable is in programming.
- How to use Events to react to enemies.
- How to code a simple "kill zone" for your turret.
How It Works
Imagine you are building a castle. You put a cannon on the wall. The cannon needs two things. First, it needs a target. Second, it needs to know when to shoot. In Fortnite Creative, we use devices for this. The Mounted Turret is a special device. It gives players a weapon. They can sit on it and shoot. It has unlimited ammo. This is great for defense!
But we want it to shoot for us. We want it to be automatic. To do this, we need Verse. Verse is the language we use to give devices instructions. Think of Verse like a recipe. You tell the computer step-by-step what to do.
We will use a Variable. A variable is like a box. It holds a value. We will use a variable to count how many enemies we defeat. This is fun! It gives us a score. We will also use an Event. An event is like a doorbell. It rings when something happens. Here, the doorbell rings when an enemy dies. We will catch that ring. Then we will add to our score.
Let's Build It
First, place a Mounted Turret device in your island. You can find it in the devices menu. Place it on a tower. Now, we need to code it. We will use a Verse script. This script will track kills. It will not make the turret shoot automatically. That is built-in. Instead, it will track your success.
Here is the code. Copy it into a Verse file.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
# This is our main script block.
# It manages the turret device and tracks score.
turret_score_manager := class(creative_device):
# We reference our Automated Turret device here.
# Drag your placed device onto this property in the editor.
@editable
Turret : automated_turret_device = automated_turret_device{}
# This is a Variable.
# It holds the current score.
# It starts at zero.
var Score : int = 0
# OnBegin runs automatically when the game starts.
OnBegin<override>()<suspends> : void =
# We wait for an Event.
# DestroyedEvent fires when the turret is destroyed, or we can use TargetFoundEvent.
# This means an enemy was hit by this turret.
loop:
# Block here until the turret finds a target (eliminates someone).
Turret.TargetFoundEvent.Await()
# When the event happens...
# Add one to our score.
set Score = Score + 1
# Print the score to the screen.
# This helps us see it working.
Print("Score: {Score}")```
Let's look at this code closely. The first lines bring in tools. They are like opening your toolbox. The `turret_score_manager` is a **class** that extends `creative_device`. A class is a set of instructions. It runs when we tell it to. The `var Score : int = 0` line creates our variable. The `Turret.EliminatedEvent.Await()` line waits for the turret to eliminate someone. When it does, it adds one to the score. Then it prints the number. This is very simple. But it works!
You might wonder about the **Scene Graph**. The scene graph is like a family tree for your game objects. The turret is a child of the island. The script is attached to the turret. This means the script knows about the turret. It can talk to it. It can listen to it. This connection is key. Without it, the script would not know who to score for.
## Try It Yourself
Now it is your turn! Try to change the code. Make the score start at 100. Or, make it print "Great Shot!" instead of the number. You can also add a second variable. Call it `BestScore`. Save it when the score gets higher. This is a great challenge. It teaches you how to store data.
Hint: Look at the `Print` line. You can put any text inside the quotes. Try adding a smiley face!
## Recap
You built a turret tracker. You used a **Mounted Turret** device. You wrote a Verse script. You learned about **Variables** and **Events**. Your turret now tracks your kills. This is just the start. You can build much more. Keep coding and have fun!
## References
- https://dev.epicgames.com/documentation/en-us/fortnite/using-mounted-turret-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-mounted-turret-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/using-heavy-turret-devices-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-heavy-turret-devices-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-mounted-turret-devices-in-fortnite-creative to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.