Strings: Length, Slicing, Name Tags

In this lesson you'll learn to

  • βœ“Measure and build strings to format racer name tags and HUD text.

Measure and build strings to format racer name tags and HUD text.

πŸ“– Reference & full walkthrough: Strings: Length, Slicing, Name Tags

πŸ” Builds on: south-shores string-interpolation lesson

🧩 Your capstone piece: Racer name-tag and lap-time text formatting


Overview

string.Length is a built-in property on every Verse string value. It returns an int equal to the number of UTF-8 code units in the string β€” which equals the number of ASCII characters for plain Latin text, but may be larger for accented or emoji characters (e.g. "JosΓ©".Length is 5, not 4).

On a UEFN island you reach for .Length whenever you need to:

  • Validate a player-supplied name or code before displaying it.
  • Gate game logic on whether a string is empty, too short, or over a character limit.
  • Drive HUD feedback β€” show a different message depending on how long the string is.
  • Truncate or slice a string by indexing into it (since string is []char in Verse).

Because string is just []char, .Length is the same as asking for the number of elements in that array β€” it's zero-indexed, so valid indices run from 0 to Length - 1.

API Reference

hud_message_device

Used to show custom HUD messages to one or more agents.

Full public surface, resolved verbatim from the live Epic digest (Fortnite.digest.verse).

hud_message_device<public> := class<concrete><final>(creative_device_base):

Events (subscribe a handler to react):

Event Signature Description
ShowMessageEvent ShowMessageEvent<public>:listenable(agent) Called when a Message has been Shown on-screen. Returns an Agent if it was Shown on a specified Agent's screen.
HideMessageEvent HideMessageEvent<public>:listenable(agent) Called when a Message has been Hidden on-screen. Returns an Agent if it was Hidden from a specified Agent's screen.
ClearAllMessagesEvent ClearAllMessagesEvent<public>:listenable(agent) Called when all queued Messages from all players that are affected by this HUD Message Device have been cleared.

Methods (call these to make the device act):

Method Signature Description
Show Show<public>(Agent:agent):void Shows the currently set HUD Message on Agents screen. Will replace any previously active message. Use this when the device is setup to target specific agents.
Show Show<public>():void Shows the currently set Message HUD message on screen. Will replace any previously active message.
Hide Hide<public>():void Hides the HUD message.
Hide Hide<public>(Agent:agent):void Hides the currently set HUD Message on Agents screen. Use this when the device is setup to target specific agents.
Show Show<public>(Agent:agent, Message:message, ?DisplayTime:float Displays a Custom message to a specific Agent that you define.Setting DisplayTime to 0.0 will display the HUD message persistently.If not defined, or less than 0.0 the message will show for the time set on the device.
Show Show<public>(Message:message, ?DisplayTime:float Displays a Custom message that you define for all PlayersSetting DisplayTime to 0.0 will display the HUD message persistently.If not defined, or less than 0.0 the message will show for the time set on the device.
SetDisplayTime SetDisplayTime<public>(Time:float):void Sets the time (in seconds) the HUD message will be displayed. 0.0 will display the HUD message persistently.
GetDisplayTime GetDisplayTime<public>()<transacts>:float Returns the time (in seconds) for which the HUD message will be displayed. 0.0 means the message is displayed persistently.
SetText SetText<public>(Text:message):void Sets the Message to be displayed when the HUD message is activated. Text is clamped to 150 characters.
ClearAllMessages ClearAllMessages<public>():void Clears all queued Messages from all players that are affected by this HUD Message Device.

trigger_device

Used to relay events to other linked devices.

Full public surface, resolved verbatim from the live Epic digest (Fortnite.digest.verse). Inherited members are merged from trigger_base_device.

trigger_device<public> := class<concrete><final>(trigger_base_device):

Events (subscribe a handler to react):

Event Signature Description
TriggeredEvent TriggeredEvent<public>:listenable(?agent) Signaled when an agent triggers this device. Sends the agent that used this device. Returns false if no agent triggered the action (ex: it was triggered through code).

Methods (call these to make the device act):

Method Signature Description
Trigger Trigger<public>(Agent:agent):void Triggers this device with Agent being passed as the agent that triggered the action. Use an agent reference when this device is setup to require one (for instance, you want to trigger the device only with a particular agent.
Trigger Trigger<public>():void Triggers this device, causing it to activate its TriggeredEvent event.
Enable Enable<public>():void Enables this device.
Disable Disable<public>():void Disables this device.
SetMaxTriggerCount SetMaxTriggerCount<public>(MaxCount:int):void Sets the maximum amount of times this device can trigger. * 0 can be used to indicate no limit on trigger count. * MaxCount is clamped between [0,20].
GetMaxTriggerCount GetMaxTriggerCount<public>()<transacts>:int Gets the maximum amount of times this device can trigger. * 0 indicates no limit on trigger count.
GetTriggerCountRemaining GetTriggerCountRemaining<public>()<transacts>:int Returns the number of times that this device can still be triggered before hitting GetMaxTriggerCount. Returns 0 if GetMaxTriggerCount is unlimited.
SetResetDelay SetResetDelay<public>(Time:float):void Sets the time (in seconds) after triggering, before the device can be triggered again (if MaxTrigger count allows).
GetResetDelay GetResetDelay<public>()<transacts>:float Gets the time (in seconds) before the device can be triggered again (if MaxTrigger count allows).
SetTransmitDelay SetTransmitDelay<public>(Time:float):void Sets the time (in seconds) which must pass after triggering, before this device informs other external devices that it has been triggered.
GetTransmitDelay GetTransmitDelay<public>()<transacts>:float Gets the time (in seconds) which must pass after triggering, before this device informs other external devices that it has been triggered.

player

Full public surface, resolved verbatim from the live Epic digest (Verse.digest.verse). Inherited members are merged from agent.

player<native><public> := class<unique><persistent><module_scoped_var_weak_map_key><epic_internal>(agent):

Walkthrough

Scenario β€” The Pirate Cove Name Board

Your 2D cel-shaded pirate cove island has a Name Board near the dock. When a player steps on a pressure plate (modelled as a trigger_device), the game reads a hard-coded alias string, checks its .Length, and flashes one of three HUD messages:

  • Too short (< 3 chars) β†’ "Arr, that name's too short, landlubber!"
  • Too long (> 12 chars) β†’ "Blimey! Trim that name to 12 letters!"
  • Just right β†’ "Welcome aboard, [name]!"

It also calls SetDisplayTime to keep the message on screen longer for the error cases, and fires a second trigger to ring the ship's bell only when the name is valid.

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

# Localized message helpers β€” required because hud_message_device.Show takes `message`, not `string`
TooShortMsg<localizes>(S : string) : message = "Arr, that name be too short, {S}!"
TooLongMsg<localizes>(S : string) : message = "Blimey! Trim yer name β€” {S} be too long!"
WelcomeMsg<localizes>(S : string) : message = "Welcome aboard, {S}!"

pirate_name_board := class(creative_device):

    # Drop a trigger_device on the dock pressure plate in UEFN and wire it here.
    @editable
    NameTrigger : trigger_device = trigger_device{}

    # A second trigger that fires the ship's bell (linked to a sound device in UEFN).
    @editable
    BellTrigger : trigger_device = trigger_device{}

    # The HUD message device placed on the island.
    @editable
    HUD : hud_message_device = hud_message_device{}

    # The alias we are validating. In a real island this could come from
    # a player_reference_device or a score manager; here we keep it simple.
    PirateAlias : string = "Blackbeard"

    OnBegin<override>()<suspends> : void =
        # Subscribe to the dock pressure plate.
        NameTrigger.TriggeredEvent.Subscribe(OnNamePlateTriggered)

    # Handler β€” called every time a player steps on the plate.
    OnNamePlateTriggered(MaybeAgent : ?agent) : void =
        Length := PirateAlias.Length

        if (Length < 3):
            # Error: name too short β€” show for 5 seconds.
            HUD.SetDisplayTime(5.0)
            HUD.Show(TooShortMsg(PirateAlias))
        else if (Length > 12):
            # Error: name too long β€” show for 5 seconds.
            HUD.SetDisplayTime(5.0)
            HUD.Show(TooLongMsg(PirateAlias))
        else:
            # Valid name β€” show for 3 seconds and ring the bell.
            HUD.SetDisplayTime(3.0)
            HUD.Show(WelcomeMsg(PirateAlias))
            # Ring the ship's bell only for a valid name.
            if (A := MaybeAgent?):
                BellTrigger.Trigger(A)
            else:
                BellTrigger.Trigger()

Line-by-line explanation

Lines What's happening
TooShortMsg / TooLongMsg / WelcomeMsg <localizes> functions convert a string into a message so hud_message_device.Show accepts them. You cannot pass a raw string to Show.
@editable fields Every device you want to call must be declared as an @editable field inside the class. A bare identifier like NameTrigger.TriggeredEvent would fail with Unknown identifier otherwise.
NameTrigger.TriggeredEvent.Subscribe(OnNamePlateTriggered) Wires the dock plate to our handler. TriggeredEvent is a listenable(?agent) so the handler receives ?agent.
Length := PirateAlias.Length .Length returns an int β€” no cast, no helper function.
HUD.SetDisplayTime(5.0) Configures how long the next Show call keeps the message visible.
HUD.Show(TooShortMsg(PirateAlias)) Broadcasts the localized message to all players.
BellTrigger.Trigger(A) / BellTrigger.Trigger() Fires the bell trigger with or without an agent depending on whether one was available.

Common patterns

Pattern 1 β€” Persistent HUD until dismissed (DisplayTime = 0.0) + Hide

Use SetDisplayTime(0.0) to pin a message to the HUD indefinitely, then call Hide when the player leaves the cove.

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

CoveWelcome<localizes>(S : string) : message = "You are in the {S} β€” explore!"
CoveFarewell<localizes>() : message = "Safe sailing, pirate!"

cove_sign_device := class(creative_device):

    @editable
    EnterTrigger : trigger_device = trigger_device{}

    @editable
    ExitTrigger : trigger_device = trigger_device{}

    @editable
    SignHUD : hud_message_device = hud_message_device{}

    CoveName : string = "Skull Lagoon"

    OnBegin<override>()<suspends> : void =
        EnterTrigger.TriggeredEvent.Subscribe(OnEnter)
        ExitTrigger.TriggeredEvent.Subscribe(OnExit)

    OnEnter(MaybeAgent : ?agent) : void =
        # Pin the location name persistently (DisplayTime = 0.0).
        # .Length lets us confirm the string is non-empty before showing.
        if (CoveName.Length > 0):
            SignHUD.SetDisplayTime(0.0)
            SignHUD.Show(CoveWelcome(CoveName))

    OnExit(MaybeAgent : ?agent) : void =
        # Hide the persistent message when the player leaves.
        if (A := MaybeAgent?):
            SignHUD.Hide(A)
        else:
            SignHUD.Hide()

Pattern 2 β€” GetDisplayTime + SetMaxTriggerCount to cap announcements

Query the current display time with GetDisplayTime, then limit how many times the trigger can fire using SetMaxTriggerCount so the lagoon announcement plays only three times per round.

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

TreasureFound<localizes>(S : string) : message = "Treasure chest found: {S}"

treasure_announce_device := class(creative_device):

    @editable
    ChestTrigger : trigger_device = trigger_device{}

    @editable
    AnnouncementHUD : hud_message_device = hud_message_device{}

    TreasureLabel : string = "Golden Anchor"

    OnBegin<override>()<suspends> : void =
        # Cap the trigger to 3 fires so the announcement doesn't spam.
        ChestTrigger.SetMaxTriggerCount(3)
        # Log the current HUD display time for reference.
        CurrentTime := AnnouncementHUD.GetDisplayTime()
        # If the designer left it at 0 (persistent), set a sensible default.
        if (CurrentTime = 0.0):
            AnnouncementHUD.SetDisplayTime(4.0)
        ChestTrigger.TriggeredEvent.Subscribe(OnChestFound)

    OnChestFound(MaybeAgent : ?agent) : void =
        # Only show the message if the label is a meaningful length.
        if (TreasureLabel.Length >= 3):
            AnnouncementHUD.Show(TreasureFound(TreasureLabel))
        Remaining := ChestTrigger.GetTriggerCountRemaining()
        if (Remaining = 0):
            AnnouncementHUD.ClearAllMessages()

Pattern 3 β€” Slicing a string with .Length to build a short-code display

Because string is []char, you can use .Length to safely iterate and build a truncated version for a HUD ticker on the clifftop scoreboard.

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

TickerMsg<localizes>(S : string) : message = ">> {S} <<"

clifftop_ticker_device := class(creative_device):

    @editable
    TickerTrigger : trigger_device = trigger_device{}

    @editable
    TickerHUD : hud_message_device = hud_message_device{}

    FullMessage : string = "Pirate King Tournament β€” Round 3 β€” Skull Cove"

    # Maximum characters to show on the HUD ticker.
    MaxChars : int = 20

    OnBegin<override>()<suspends> : void =
        TickerTrigger.TriggeredEvent.Subscribe(OnTick)

    OnTick(MaybeAgent : ?agent) : void =
        Len := FullMessage.Length
        # Clamp the slice end to whichever is smaller.
        SliceEnd := if (Len < MaxChars) then Len else MaxChars
        # Build the truncated string by slicing the []char array.
        Truncated : string = FullMessage[0..SliceEnd]
        TickerHUD.SetText(TickerMsg(Truncated))
        TickerHUD.Show()

Gotchas

1. .Length counts UTF-8 code units, not Unicode characters

"JosΓ©".Length returns 5, not 4, because the accented Γ© is encoded as two UTF-8 code units. If you are validating user-visible character counts, add a comment explaining this so future editors don't introduce an off-by-one.

2. Show(message) requires a <localizes> function β€” not a raw string

hud_message_device.Show and SetText both take a message type. You cannot pass a string directly. Always wrap with a <localizes> helper:

MyLabel<localizes>(S : string) : message = "{S}"

There is no StringToMessage function in Verse.

3. TriggeredEvent sends ?agent, not agent

The handler signature must be (MaybeAgent : ?agent). Unwrap before passing to BellTrigger.Trigger(A) or HUD.Hide(A):

if (A := MaybeAgent?):
    BellTrigger.Trigger(A)

Forgetting the ? in the handler signature is a compile error.

4. SetDisplayTime(0.0) means persistent, not "instant"

Passing 0.0 to SetDisplayTime pins the message on screen until Hide or ClearAllMessages is called. This is intentional but easy to misread as "zero seconds".

5. SetMaxTriggerCount is clamped to [0, 20]

Values outside that range are silently clamped. 0 means unlimited, not zero triggers. Use GetTriggerCountRemaining() to check how many fires are left β€” it returns 0 when the limit is unlimited.

6. int vs float β€” no auto-conversion

string.Length returns int. SetDisplayTime and GetDisplayTime take/return float. Verse does not auto-convert between them. If you compute a display time from a length, cast explicitly:

DisplaySecs : float = Float(PirateAlias.Length) * 0.5
HUD.SetDisplayTime(DisplaySecs)

The Float() built-in converts an int to a float.

πŸ”’

Keep going β€” free

You've read the intro. The rest of this lesson is free for members. Sign in to continue and track your progress.

Sign in free to continue this lesson
Pass the quiz above to chart this quest in your Journal.

Sources

/guides/string-length
Source

Biloxi Studios original lesson

Guided course

Add this lesson to your free study plan.

🧭 The Keeper’s log

Quest complete? Chart your next heading from the 🐻 North Jungle expedition.

β›΅ Take me there