In this step, you will create a timer system in Verse that uses the Timer and End Game devices. The timer will start when the player hits any target, and the game will end and display the scoreboard when it runs out.
While you can end your game on a timer with Island Settings or with devices alone, using Verse increases your control over the game mechanics you use.
Modify Your Island
Select the Island Settings device in the viewport or Outliner panel.
In the Details panel, set the following parameters:
Uncheck Stat to End. This removes the original scoring end condition, which you will replace with the timer.
Set Game Score Display Time to 10 seconds.
Enable First Scoreboard Column, then set to Score.
Use the Content Browser to find the Timer Device, then drag it into the viewport.
In the Details panel, set Visible During Game to Hidden. This hides the timer object during the game, but the time still displays on the player's HUD while it is active.
Use the Content Browser to find the End Game Device, then drag it into the viewport.
Write Verse Code
This page guides you step by step through the code changes, but if you want to check your work, review the Complete Code section for the final result.
Open the
shooting_range_manager_device.versefile.Add the following variables to store the new device references and a logic flag to track the timer's state.
A flag variable refers to a variable in your code that exists to track if a certain condition has been met.
IsTimerStartedis the flag here where false represents ‘no’, and true represents yes.Verse@editable Timer:timer_device = timer_device{} @editable EndGame:end_game_device = end_game_device{} var IsTimerStarted:logic = falseAdd the
OnTimerSuccesscallback method, which will be called when the timer runs out to end the game.The OnTimerSuccess method receives an optional agent parameter, which is the agent that activated the timer, if any. The End Game device requires a non-option agent parameter to activate, so the optional agent is converted to non-optional in the
ifstatement. See option for more information on option types.Verse# When time runs out, end the game. OnTimerSuccess(Agent:?agent):void= if (TriggerAgent := Agent?): EndGame.Activate(TriggerAgent)Add the StartTimer method that sets up the timer's subscription to the OnTimerSuccess callback and starts the timer.
Verse# Setup and start the timer. StartTimer():void= # Set the event subscription to call OnTimerSuccess when the timer finishes. Timer.SuccessEvent.Subscribe(OnTimerSuccess) # Start the timer. Timer.Start() # Track that the timer has started. set IsTimerStarted = trueModify the AdjustScore method to start the timer. This gives the player a moment to ready their first shot to begin the game.
Verse# Adjusts the player's score by the provided value. AdjustScore(Value:int):void= <# --- New Code Start --- #> # Start the timer if it hasn't started yet. if (not IsTimerStarted?): StartTimer() <# --- New Code End --- #>Save and build your Verse code.
Complete Code
using { /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{}
@editable
Bring It Together
Select the shooting_range_manager_device in the viewport or Outliner panel.
In the Details panel, set the following parameters:
Set Timer to the Timer device.
Set EndGame to the End Game device.
Push your changes and playtest your island.
Verify the timer starts when shooting any target.
Verify that once the timer runs out, the game ends and displays the scoreboard.