Overview
Summing an array is one of the most common jobs in a Fortnite island: you keep a list of per-player scores, per-round times, or per-chest values, and you need the total. There is no sum_an_array_device — Verse arrays already give you everything. You store your numbers in a []int (or []float), and you write a small function that loops with for and accumulates a running total.
Reach for this pattern whenever you catch yourself thinking "how many altogether?" — total coins on the dock, combined seconds across three race laps, sum of damage dealt. In our worked example, a sunny cove has three glowing shell-plates; each plate is a placed device that fires an event when a player stomps it. Every stomp appends a value to an array, and we sum that array to light up a VFX celebration when the beach reaches its treasure quota.
The device APIs we actually call to make this a game (not just math) are InteractedWithEvent on a button (the shell-plate stomp), and the vfx_spawner_device (Enable, Disable, Restart) for the celebration burst.
API Reference
(API surface could not be resolved for this device.)
Walkthrough
Here's the full cove scenario. Three shell-plate buttons each hold a point value. When a player stomps a plate, we push that value onto a Scores array, sum the whole array, and once the total reaches our quota we fire a VFX burst on the shore.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Fortnite.com }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
cove_tally_device := class(creative_device):
# The three shell-plates players stomp. Buttons fire InteractedWithEvent.
@editable
PlateA : button_device = button_device{}
@editable
PlateB : button_device = button_device{}
@editable
PlateC : button_device = button_device{}
# Celebration burst on the shore when the quota is hit.
@editable
CelebrationVfx : vfx_spawner_device = vfx_spawner_device{}
# How many treasure-points the cove needs before we celebrate.
@editable
Quota : int = 30
# The running list of point values earned this round.
var Scores : []int = array{}
# Reusable helper: walk an array of ints and return the total.
Sum(Nums:[]int):int =
var Total:int = 0
for (N : Nums):
set Total += N
Total
OnBegin<override>()<suspends>:void =
# Keep the burst off until the cove earns it.
CelebrationVfx.Disable()
# Each plate contributes a different point value.
PlateA.InteractedWithEvent.Subscribe(OnStompedA)
PlateB.InteractedWithEvent.Subscribe(OnStompedB)
PlateC.InteractedWithEvent.Subscribe(OnStompedC)
# Handlers append a value, then re-check the running sum.
OnStompedA(Agent:agent):void =
set Scores += array{5}
CheckTotal()
OnStompedB(Agent:agent):void =
set Scores += array{10}
CheckTotal()
OnStompedC(Agent:agent):void =
set Scores += array{15}
CheckTotal()
CheckTotal():void =
Total := Sum(Scores)
Print("Cove total so far: {Total}")
if (Total >= Quota):
# Quota met — light up the shore!
CelebrationVfx.Enable()
CelebrationVfx.Restart()
Line by line:
- The four
@editabledevice fields let you drop the three buttons and one VFX spawner into the slots in UEFN. A device is unreachable from Verse unless it's an@editablefield like this. Quota : int = 30is a tunable number you can edit per-map without touching code.var Scores : []int = array{}is our accumulator array.array{}needs the[]intannotation so Verse knows the element type.Sum(Nums:[]int):intis the star:var Totalstarts at 0, thefor (N : Nums)loop visits every element,set Total += Naccumulates, and the last expressionTotalis the return value. This is the canonical sum-an-array pattern.- In
OnBegin,CelebrationVfx.Disable()hides the effect, then we subscribe each plate'sInteractedWithEventto its handler. Subscriptions belong inOnBegin. - Each
OnStomped*handler is a method taking(Agent:agent)— the shapeInteractedWithEventhands you. Weset Scores += array{...}to append a value, then callCheckTotal. CheckTotalcallsSum(Scores), prints the tally for debugging, and when the sum meets the quota callsEnable()thenRestart()to fire the burst VFX.
Common patterns
Summing floats (lap times) instead of ints
Same loop, but a []float because race times are fractional. Note int and float never auto-convert, so the accumulator must also be float.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Fortnite.com }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
lap_tally_device := class(creative_device):
@editable
FinishPlate : button_device = button_device{}
var LapTimes : []float = array{}
SumFloats(Nums:[]float):float =
var Total:float = 0.0
for (N : Nums):
set Total += N
Total
OnBegin<override>()<suspends>:void =
FinishPlate.InteractedWithEvent.Subscribe(OnLapDone)
OnLapDone(Agent:agent):void =
# Pretend each stomp records a 12.5s lap.
set LapTimes += array{12.5}
TotalTime := SumFloats(LapTimes)
Print("Combined race time: {TotalTime}")
Summing point values gathered from tagged props
Use GetCreativeObjectsWithTag to collect every treasure prop on the beach, count them into an array of fixed values, then sum. Here every tagged object is worth one point.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Fortnite.com }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
treasure_count_device := class(creative_device):
@editable
StartPlate : button_device = button_device{}
Sum(Nums:[]int):int =
var Total:int = 0
for (N : Nums):
set Total += N
Total
OnBegin<override>()<suspends>:void =
StartPlate.InteractedWithEvent.Subscribe(OnCount)
OnCount(Agent:agent):void =
Treasures := GetCreativeObjectsWithTag(tag{})
# Build an array of 1s, one per treasure, then sum to get the count.
var Points : []int = array{}
for (_ : Treasures):
set Points += array{1}
Print("Treasures on the cove: {Sum(Points)}")
Summing a live scoreboard array and reacting
Keep per-round scores in an array, sum after each round, and toggle a VFX when the beach beats its best.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Fortnite.com }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
scoreboard_device := class(creative_device):
@editable
RoundPlate : button_device = button_device{}
@editable
WinVfx : vfx_spawner_device = vfx_spawner_device{}
var RoundScores : []int = array{}
Sum(Nums:[]int):int =
var Total:int = 0
for (N : Nums):
set Total += N
Total
OnBegin<override>()<suspends>:void =
WinVfx.Disable()
RoundPlate.InteractedWithEvent.Subscribe(OnRoundEnd)
OnRoundEnd(Agent:agent):void =
set RoundScores += array{7}
if (Sum(RoundScores) > 20):
WinVfx.Enable()
WinVfx.Restart()
Gotchas
- Empty
array{}needs a type.var Scores := array{}fails — Verse can't infer the element type. Always annotate:var Scores : []int = array{}. intandfloatnever auto-convert. If your data is floats, your accumulator must start at0.0and yourSummust returnfloat. Mixing them is a compile error.- Appending is
set Arr += array{x}, notArr.Add(x). Verse arrays are immutable values; you produce a new array with+=on avar. - Subscribe in
OnBegin, handle at class scope.InteractedWithEvent.Subscribe(OnStompedA)must run insideOnBegin, andOnStompedAmust be a method on the class taking(Agent:agent). - Devices must be
@editablefields. CallingPlateA.InteractedWithEventonly works becausePlateAis a field you wired up in UEFN — a bare local device reference gives 'Unknown identifier'. vfx_spawner_device.Restart()re-triggers burst effects. For a one-shot celebration,Enable()thenRestart()guarantees the burst plays even if it was already enabled.- The last expression in
Sumis the return. Don't add a strayreturn; in Verse the trailingTotalon its own line is the returned value.