The Clock is Ticking: Building Dynamic Timers with Verse
Unverified — this example may not compile as-is.
The Verse code below did not pass our automated compile check, so it isn't marked verified and is hidden from the guide listing. The explanation may still be useful, but treat the code as a draft and adapt it before use.
The Clock is Ticking: Building Dynamic Timers with Verse
So, you’ve got your island, you’ve got your traps, but everything feels... static. It just is. You want chaos. You want a countdown that actually matters, a timer that ticks down while you’re trying to edit a wall, or a grind rail that rewards patience. That’s where Timers come in. In Fortnite Creative, a Timer device is like the storm’s internal clock—it tracks time passing to trigger events. But in Verse, we don’t just place a device and hope for the best; we write code to make those timers talk to each other, add time when you press a button, and keep the game running smoothly.
In this tutorial, we’re going to build a "Revenge Timer" system. Imagine a trap that counts down to an explosion, but if you smash a button, it adds more time to keep the pressure on. We’ll learn how to use Variables (containers that change) and Functions (actions you call) to make it happen.
What You'll Learn
- Variables: How to store changing values (like time remaining) in your code.
- Functions: How to package up actions (like adding time) so you can reuse them.
- Events: How to make your code react when a player clicks a button.
- The Scene Graph: Where these pieces live in your island’s hierarchy.
How It Works
Before we write a single line of Verse, let’s map this to mechanics you already know.
1. The Variable: Your Health Bar
Think of a Variable as your health bar. It’s a container that holds a number, and that number changes during the game. When you take damage, the number goes down. When you eat a shield potion, it goes up. In our code, we’ll create a variable called RemainingTime. It starts at, say, 30 seconds. Every second, it goes down by 1.
2. The Function: Using an Item
Think of a Function as using an item from your inventory. You don’t just "have" a shield potion; you use it. Using it triggers a specific set of actions: the potion disappears, and your health goes up. In Verse, we’ll create a function called AddTime. When we "call" (use) this function, it takes a number (how many seconds to add) and updates our RemainingTime variable.
3. The Event: The Trigger
Think of an Event as a trigger pad. Nothing happens when you stand near it. But the moment you step on it, something happens (like a trap springing or a door opening). In Verse, we’ll listen for the "Button Pressed" event. When that event fires, our code will kick in and call the AddTime function.
4. The Scene Graph: Your Loadout
The Scene Graph is like your loadout screen. It shows you all the devices (props, traps, timers) you have placed in your island, organized by where they are. In Verse, we don’t just grab random devices; we reference specific ones in this hierarchy. We’ll tell Verse: "Hey, when the button is pressed, look at the Timer device in the scene graph and tell it to update."
Let's Build It
We’re going to create a simple script that manages a countdown. We’ll use a Button device to add time to a Timer device.
Step 1: Set Up Your Devices
- Place a Button device in your island. Name it
RevengeButton. - Place a Timer device nearby. Name it
CountdownTimer.- Settings: Set Duration to
30.0seconds. Set Countdown Direction to Count Down. Set Visible During Game to Hidden (we’ll show the time on screen, not the device). Set Show on HUD to No (we’ll handle the UI ourselves).
- Settings: Set Duration to
- (Optional) Place a Prop Mover or a Trap that triggers when the timer completes, so you have something to explode when time runs out.
Step 2: The Verse Code
Create a new Verse file called RevengeTimer.verse. Paste this code in. Don’t worry about memorizing it yet; we’ll break it down line by line.
# This is our main script file.
# It lives in the Scene Graph under our island's main actor.
using { /Fortnite.com/Devices }
using { /Verse.org/Sim }
using { /UnrealEngine.com/Temporary/Schemas }
# We define a "RevengeTimer" structure. Think of this as the blueprint for our timer system.
RevengeTimer = struct(
# This variable holds the current time left. It's like your health bar.
RemainingTime : float = 30.0,
# This references the Timer device in our scene graph.
# It's like pointing to a specific prop in your inventory.
TimerDevice : TimerDevice,
# This references the Button device.
ButtonDevice : ButtonDevice,
# This is a placeholder for the UI text we'll show on screen.
# We'll use a simple print for now to keep it beginner-friendly.
TimeDisplay : string = "Time: 30"
)
# This is the FUNCTION. It's like using an item.
# It takes a parameter (TimeToAdd) and does something with it.
.AddTime := (TimeToAdd : float) -> void =
(
# Update the RemainingTime variable.
# This is like eating a shield potion: the value changes.
RemainingTime += TimeToAdd
# Make sure the time doesn't go below zero (no negative health!)
if (RemainingTime < 0.0) {
RemainingTime = 0.0
}
# Update the display string so we know what's happening.
TimeDisplay = "Time: " + ToString(Round(RemainingTime))
# In a full game, you'd update the HUD here.
# For now, we'll just print to the debug console.
Print(TimeDisplay)
# If the timer device exists, tell it to update its visual state.
# This keeps the device in sync with our code variable.
if (TimerDevice != TimerDevice{}) {
TimerDevice.SetTime(RemainingTime)
}
)
# This is the EVENT listener. It's like standing on a trigger pad.
# When the button is pressed, this code runs.
.OnButtonPressed := (event : ButtonPressedEvent) -> void =
(
# Call the AddTime function and add 10 seconds!
# This is like pressing the button to activate the item.
.AddTime(10.0)
)
# This is the INIT function. It runs once when the game starts.
# It's like the pre-game lobby setup.
.Init := () -> void =
(
# Print a message to confirm our script is loaded.
Print("Revenge Timer Loaded! Smash the button to add time.")
# Initialize the timer device with our starting time.
if (TimerDevice != TimerDevice{}) {
TimerDevice.SetTime(RemainingTime)
}
)
Step 3: Connecting the Dots
- In UEFN, select your main island actor (or the actor you’re attaching this script to).
- In the Verse panel, select
RevengeTimer.verse. - In the Details panel, you’ll see fields for
TimerDeviceandButtonDevice. Drag and drop the devices you placed in Step 1 into these slots. This links your code to the actual devices in the scene graph.
Step 4: Playtest
Hit Play. You should see the debug print saying "Revenge Timer Loaded!" When you press the button, the time should add 10 seconds, and the print statement should update. If you wait for the timer to hit 0, your trap should trigger (if you set one up).
Try It Yourself
Challenge: Modify the code so that when the timer hits 0, it doesn’t just stop. Instead, it resets to 30 seconds automatically and prints "Round Reset!" to the console.
Hint: You’ll need to create a new function called .ResetTimer() that sets RemainingTime back to 30.0 and calls .AddTime(0) to update the display. Then, you’ll need to trigger this function when the timer completes. Look into the TimerDevice’s OnComplete event in the Verse documentation.
Recap
- Variables are containers that change, like your health or shield. We used
RemainingTimeto track seconds. - Functions are reusable actions, like using an item. We built
.AddTime()to update our variable and display. - Events are triggers that start code, like stepping on a pad. We listened for
ButtonPressedEventto call our function. - The Scene Graph is where your devices live. We linked our code to the actual
TimerDeviceandButtonDevicein the editor.
You’ve just built a dynamic, interactive timer system. No more static countdowns. Now go make some chaos.
References
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/grind-rail-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite/making-a-custom-countdown-timer-using-verse
- https://dev.epicgames.com/documentation/en-us/fortnite/grind-rail-device-design-example-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/fortnite-creative/orbit-camera-device-design-examples-in-fortnite-creative
- https://dev.epicgames.com/documentation/en-us/uefn/custom-countdown-timer-in-verse
Verse source files
- 01-standalone.verse · standalone
Turn this into a guided course
Add Add the Timers 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.