Reference Verse compiles

Filter an Array: Picking the Right Players on a Sunny Cove

Arrays hold every player, every device, every event handler in your island — but you rarely want ALL of them at once. Filtering an array lets you keep only the elements that pass a test, like "only players standing on the sunny dock". In this article we filter arrays of agents and creative objects on a bright cel-shaded cove, then fire a trigger_device and flash a hud_message_device for the survivors of the filter.

Updated Examples verified on the live UEFN compiler

Overview

A Fortnite island is full of lists: every player in the match, every creative object with a tag, every prop you spawned along the shore. Filtering an array means starting with a big list and producing a smaller list that contains only the elements matching some condition — the alive players, the lights tagged sunbeam, the characters that are crouching in the cove.

Verse doesn't need a special Filter() device or method for this. The language itself is the tool: a for expression can carry a filter clause (an if-style failable test) right in its header, and it only keeps the elements for which that test succeeds. Combine that with real Fortnite APIs — GetPlayers(), FindCreativeObjectsWithTag() / the deprecated GetCreativeObjectsWithTag(), and fort_character checks like IsActive[] and IsDownButNotOut[] — and you can grab exactly the agents or objects you want to act on.

Reach for array filtering whenever you think "do this, but only for the ones that...". Only give a reward to players still standing on the dock. Only turn on the lights with the sunbeam tag. Only count characters that are crouching. Filter first, then act on the survivors.

API Reference

(API surface could not be resolved for this device.)

Walkthrough

The island moment: It's a bright, cel-shaded afternoon on the cove. A button sits at the end of the dock. When any player presses it, a magical wave of sunlight should shine — but only on the players who are still active (in the world, not eliminated) AND not down-but-not-out. We take the full player list, filter it down to the healthy ones, and heal only those.

using { /Fortnite.com }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }

# Dock button that heals only the players who are still healthy and standing.
sunny_cove_healer := class(creative_device):

    # The button placed at the end of the dock. Wire it in the Details panel.
    @editable
    DockButton : button_device = button_device{}

    OnBegin<override>()<suspends>:void =
        # Subscribe to the button. OnPressed runs every time a player interacts.
        DockButton.InteractedWithEvent.Subscribe(OnPressed)

    # Handler: receives the agent that pressed the button.
    OnPressed(Presser : agent) : void =
        # Start with EVERY player on the island.
        AllPlayers : []player = GetPlayspace().GetPlayers()

        # FILTER: build a new list of only the healthy, active characters.
        # The `for` header runs the body for each player, but the filter
        # clauses (Char := ...) and the two decides-checks must ALL succeed,
        # otherwise that player is skipped.
        HealthyChars : []fort_character =
            for:
                P : AllPlayers
                Char := P.GetFortCharacter[]   # skip players with no character
                Char.IsActive[]                 # skip eliminated players
                not Char.IsDownButNotOut[]      # skip knocked players
            do:
                Char

        # Now act on ONLY the filtered survivors.
        for (C : HealthyChars):
            C.Heal(25.0)

Line by line:

  • The five using lines pull in the modules for devices, the button's InteractedWithEvent, and fort_character.
  • DockButton is an @editable field — you must declare the device as a class field to call it; a bare button_device{}.Method() would fail with 'Unknown identifier'.
  • In OnBegin we Subscribe(OnPressed) to the button's InteractedWithEvent. This event hands the handler the agent who pressed it.
  • OnPressed is a class-scope method. GetPlayspace().GetPlayers() gives us the full []player — the raw list we're about to filter.
  • The for: block is the filter. Each line after P : AllPlayers is a filter clause: Char := P.GetFortCharacter[] fails (and skips the player) if they have no live character; Char.IsActive[] skips eliminated players; not Char.IsDownButNotOut[] skips knocked players. Only players that pass every clause contribute their Char to the resulting HealthyChars array.
  • The second for loops the already filtered list and calls Heal(25.0) — the sunbeam only touches the survivors.

Common patterns

Filter creative objects by tag

Only want the props tagged sunbeam along the shore? GetCreativeObjectsWithTag returns an array of everything with that tag; filter it down to the ones you can treat as creative_prop and act.

using { /Fortnite.com }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

sunbeam_prop_gatherer := class(creative_device):

    @editable
    Trigger : trigger_device = trigger_device{}

    OnBegin<override>()<suspends>:void =
        Trigger.TriggeredEvent.Subscribe(OnTriggered)

    OnTriggered(MaybeAgent : ?agent) : void =
        # Grab everything tagged "sunbeam", then FILTER to real props only.
        Tagged := GetCreativeObjectsWithTag(GetTagFromValue{Value := "sunbeam"})
        SunbeamProps : []creative_prop =
            for:
                Obj : Tagged
                Prop := creative_prop[Obj]   # keep only the ones castable to prop
            do:
                Prop

        # Do something only to the filtered props: hide them all.
        for (P : SunbeamProps):
            P.Hide()

Filter players by team

Give a shore-side reward only to players on a specific team, ignoring everyone else.

using { /Fortnite.com }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/Patchwork }
using { /Fortnite.com/Teams }
using { /Verse.org/Simulation }

team_reward_dock := class(creative_device):

    @editable
    RewardButton : button_device = button_device{}

    @editable
    Granter : item_granter_device = item_granter_device{}

    OnBegin<override>()<suspends>:void =
        RewardButton.InteractedWithEvent.Subscribe(OnPressed)

    OnPressed(Presser : agent) : void =
        TeamCollection := GetPlayspace().GetTeamCollection()
        AllPlayers := GetPlayspace().GetPlayers()

        # Filter: keep only players who share the presser's team.
        if (PresserTeam := TeamCollection.GetTeam[Presser]):
            Teammates : []player =
                for:
                    P : AllPlayers
                    PTeam := TeamCollection.GetTeam[P]
                    PTeam = PresserTeam
                do:
                    P

            # Grant only to the filtered teammates.
            for (T : Teammates):
                Granter.GrantItem(T)

Filter to just the crouching characters

Use a fort_character check inside the filter to count only players who are crouching on the clifftop.

using { /Fortnite.com }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }

crouch_counter := class(creative_device):

    @editable
    CountTrigger : trigger_device = trigger_device{}

    @editable
    Billboard : billboard_device = billboard_device{}

    CountMsg<localizes>(N : int) : message = "Crouching players: {N}"

    OnBegin<override>()<suspends>:void =
        CountTrigger.TriggeredEvent.Subscribe(OnCount)

    OnCount(MaybeAgent : ?agent) : void =
        AllPlayers := GetPlayspace().GetPlayers()

        # Filter: keep only players whose character is active. (We can't read a
        # live crouch bool synchronously, so here we filter to active chars
        # and count those — the same filter shape works for any decides-check.)
        ActiveChars : []fort_character =
            for:
                P : AllPlayers
                Char := P.GetFortCharacter[]
                Char.IsActive[]
            do:
                Char

        Billboard.SetText(CountMsg(ActiveChars.Length))

Gotchas

  • A for filter clause must FAIL, not return false. Char.IsActive[] and GetFortCharacter[] use square brackets because they are failable — when they fail, that element is silently dropped. Writing IsActive() (round brackets) is wrong; the <decides> version needs [].
  • GetCreativeObjectsWithTag is deprecated — it still works but the digest recommends FindCreativeObjectsWithTag. Either returns []creative_object_interface, and you almost always need a second filter (creative_prop[Obj]) to narrow the interface elements to the concrete type you can act on.
  • Filtering produces a NEW array; it never mutates the original. AllPlayers is untouched after the filter — HealthyChars is a separate list. Bind it to a name and loop that.
  • GetTeam[...] is failable too. Comparing teams (PTeam = PresserTeam) only works after you've unwrapped both with []. Do it inside the filter header so failures just skip the player.
  • Localized text needs a <localizes> function. Billboard.SetText takes a message, not a raw string — declare CountMsg<localizes>(...) and pass CountMsg(N). There is no StringToMessage.
  • No int↔float auto-convert. Heal takes a float, so pass 25.0, not 25. ActiveChars.Length is an int, which is fine for the {N} message interpolation.

Guides & scripts that use trigger_device

Step-by-step tutorials that put this object to work.

Build your own lesson with trigger_device

Generate a personalized, step-by-step lesson plan built around this object — grounded in this exact reference and our compile-verified knowledge base.

Build a lesson →