VerseIsland
Feed Learn Leaderboard Guides Reference Explore Search Docs Verse Library
Sign in
Feed Learn 📖 Codex Leaderboard Guides Reference Explore Search Docs Verse Library
Verse Library › Devices
Browse Verse Library

Library

Devices 634
  • Devices171
  • Triggers & Logic118
  • UI & HUD40
  • Audio39
  • Items & Inventory29
  • Events27
  • Scoring & Objectives25
  • Spawning19
  • Classes & Interfaces18
  • Game Modes17
  • Props & Meshes14
  • Variables & Mutability12
  • Player Management11
  • Modules & Structure10
  • Round Flow8
  • Animation6
  • Concurrency6
  • Functions6
  • Getting Started6
  • Teams & Classes6
  • NPCs & AI5
  • Tutorials5
  • VFX & Particles5
  • Arrays & Maps4
  • Cameras4
  • Debugging4
  • Control Flow3
  • Cinematics2
  • Other2
  • Persistence2
  • Scene Graph2
  • Structs & Enums2
  • Building1
  • Physics1
  • Publishing & Islands1
  • Syntax & Types1
  • Vehicles1
  • Weapons1
Verse Language 257
  • Control Flow35
  • Functions26
  • Arrays & Maps25
  • Classes & Interfaces22
  • Variables & Mutability22
  • Concurrency21
  • Syntax & Types18
  • Modules & Structure12
  • Debugging8
  • Devices8
  • Events7
  • Player Management6
  • Structs & Enums6
  • Triggers & Logic6
  • Game Modes5
  • Failure & Options4
  • Scene Graph4
  • UI & HUD4
  • Getting Started3
  • Round Flow3
  • Spawning3
  • VFX & Particles3
  • Reference2
  • Animation1
  • Best Practices1
  • Other1
  • Props & Meshes1
Materials/VFX 154
  • Triggers & Logic27
  • UI & HUD17
  • Devices16
  • VFX & Particles14
  • Props & Meshes11
  • Scoring & Objectives9
  • Game Modes7
  • Items & Inventory7
  • Functions6
  • Arrays & Maps5
  • Animation3
  • Cinematics3
  • Classes & Interfaces3
  • Control Flow3
  • Events3
  • Modules & Structure3
  • Round Flow3
  • Spawning3
  • Getting Started2
  • Scene Graph2
  • Variables & Mutability2
  • Concurrency1
  • Persistence1
  • Player Management1
  • Structs & Enums1
  • Syntax & Types1
General 153
  • Devices22
  • Events20
  • Triggers & Logic20
  • Classes & Interfaces10
  • Variables & Mutability8
  • Round Flow6
  • Scoring & Objectives6
  • UI & HUD6
  • Functions5
  • Player Management5
  • Game Modes4
  • Getting Started4
  • Props & Meshes4
  • Control Flow3
  • Syntax & Types3
  • VFX & Particles3
  • Arrays & Maps2
  • Best Practices2
  • NPCs & AI2
  • Other2
  • Physics2
  • Scene Graph2
  • Spawning2
  • Structs & Enums2
  • Tutorials2
  • Building1
  • Cameras1
  • Cinematics1
  • Failure & Options1
  • Items & Inventory1
  • Teams & Classes1
Player 133
  • Player Management22
  • Teams & Classes19
  • Classes & Interfaces12
  • Devices11
  • Events9
  • Persistence7
  • Triggers & Logic7
  • Arrays & Maps6
  • Functions4
  • Game Modes4
  • Items & Inventory4
  • Round Flow4
  • Debugging3
  • Getting Started3
  • Modules & Structure3
  • Concurrency2
  • Control Flow2
  • Scoring & Objectives2
  • Spawning2
  • Structs & Enums2
  • Physics1
  • Props & Meshes1
  • UI & HUD1
  • Variables & Mutability1
  • Weapons1
Building & Props 131
  • Variables & Mutability15
  • Props & Meshes14
  • Triggers & Logic12
  • Classes & Interfaces10
  • Devices10
  • UI & HUD10
  • Events7
  • Teams & Classes7
  • Animation5
  • Building5
  • Functions5
  • VFX & Particles5
  • Structs & Enums4
  • Control Flow3
  • Game Modes3
  • Items & Inventory3
  • Round Flow3
  • Scene Graph3
  • Arrays & Maps2
  • Concurrency2
  • Reference2
  • Modules & Structure1
NPCs & AI 76
  • NPCs & AI35
  • Spawning7
  • Animation5
  • Variables & Mutability5
  • Classes & Interfaces3
  • Debugging3
  • UI & HUD3
  • Audio2
  • Concurrency2
  • Game Modes2
  • Props & Meshes2
  • Triggers & Logic2
  • Devices1
  • Functions1
  • Getting Started1
  • Reference1
  • VFX & Particles1
Spawning 73
  • Spawning31
  • Events7
  • Concurrency6
  • Player Management6
  • Vehicles5
  • Props & Meshes4
  • Devices3
  • Scene Graph3
  • Items & Inventory2
  • Teams & Classes2
  • Control Flow1
  • Publishing & Islands1
  • Reference1
  • Scoring & Objectives1
Cinematics 71
  • Cameras19
  • Cinematics15
  • Devices11
  • Audio5
  • Animation4
  • Triggers & Logic4
  • Functions2
  • Game Modes2
  • UI & HUD2
  • Classes & Interfaces1
  • Concurrency1
  • Control Flow1
  • Items & Inventory1
  • Modules & Structure1
  • Scene Graph1
  • Templates1
UI 57
  • UI & HUD35
  • Devices5
  • Scoring & Objectives4
  • Classes & Interfaces3
  • Round Flow2
  • Scene Graph2
  • Arrays & Maps1
  • Props & Meshes1
  • Structs & Enums1
  • Templates1
  • Triggers & Logic1
  • Variables & Mutability1
Scene Graph 40
  • Scene Graph9
  • Items & Inventory8
  • Classes & Interfaces3
  • Events3
  • Props & Meshes3
  • Functions2
  • Arrays & Maps1
  • Building1
  • Control Flow1
  • Debugging1
  • Modules & Structure1
  • Player Management1
  • Reference1
  • Structs & Enums1
  • Syntax & Types1
  • Triggers & Logic1
  • UI & HUD1
  • VFX & Particles1
Vehicles 38
  • Spawning11
  • Devices7
  • Vehicles7
  • Props & Meshes4
  • Functions2
  • Game Modes2
  • Failure & Options1
  • Items & Inventory1
  • Reference1
  • Teams & Classes1
  • Tutorials1
Tutorials 37
  • Game Modes6
  • Triggers & Logic5
  • Classes & Interfaces4
  • Events4
  • Props & Meshes3
  • Building2
  • Devices2
  • Items & Inventory2
  • Scoring & Objectives2
  • Animation1
  • Arrays & Maps1
  • Cameras1
  • Concurrency1
  • Physics1
  • Player Management1
  • Structs & Enums1
Weapons 30
  • Game Modes6
  • Weapons6
  • Devices5
  • Items & Inventory3
  • Scoring & Objectives3
  • Spawning2
  • Teams & Classes2
  • Best Practices1
  • Functions1
  • Triggers & Logic1
Items 28
  • Items & Inventory23
  • Devices2
  • Triggers & Logic2
  • Spawning1
Assets 20
  • Modules & Structure6
  • Arrays & Maps3
  • Functions3
  • Scene Graph2
  • Best Practices1
  • Devices1
  • Events1
  • Failure & Options1
  • Physics1
  • Variables & Mutability1
Animation 19
  • Animation10
  • Variables & Mutability4
  • Devices1
  • Player Management1
  • Props & Meshes1
  • Scene Graph1
  • Syntax & Types1
Release Notes 17
  • Classes & Interfaces5
  • Modules & Structure3
  • Concurrency2
  • Control Flow2
  • Variables & Mutability2
  • Debugging1
  • Devices1
  • Items & Inventory1
Input & Controls 16
  • Functions4
  • UI & HUD3
  • Control Flow2
  • Animation1
  • Arrays & Maps1
  • Cinematics1
  • Debugging1
  • Devices1
  • Events1
  • Items & Inventory1
Publishing 8
  • Control Flow5
  • Arrays & Maps1
  • Devices1
  • Syntax & Types1
Audio 7
  • Audio5
  • UI & HUD2
Landscape 7
  • Other4
  • VFX & Particles2
  • Scene Graph1
Persistence 6
  • Structs & Enums2
  • Items & Inventory1
  • Persistence1
  • Publishing & Islands1
  • Variables & Mutability1
Physics 5
  • Functions2
  • Classes & Interfaces1
  • Devices1
  • Syntax & Types1
Creator Economy 3
  • Publishing & Islands2
  • Modules & Structure1
Discovery 3
  • Devices1
  • NPCs & AI1
  • Structs & Enums1
Editor & Project 3
  • Other1
  • Props & Meshes1
  • Tutorials1

Santa's Toy Factory Utility Module

Santa's Toy Factory — Utility Module

A grab-bag of reusable helpers: an event wrapper that smuggles extra data to listeners (SubscribeAgent), generic map/array extension methods (RemoveKey, RemoveAll), <localizes> message builders, number padding, a float ToString(Decimals), a hand-rolled ParseInt, and a keyframe-driven prop Shake. Teaches parametric types, extension functions, and localization.

From the Santa's Toy Factory Epic starter project (SampleVerse/SantaToyFactory/utility_module.verse). Epic Games reference Verse, shown for study.

# This file defines the utility module that contains a number of extension functions, constants and functions for performing various tasks.

using { /Fortnite.com/Devices }
using { /Fortnite.com/Devices/CreativeAnimation }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Random }
using { /Verse.org/Simulation }

Utility<public> := module:

    # The factor to convert from LEGO® units (knobs) to Fortnite units (centimeters)
    LEGOUnitsToFortniteUnits<public> : float = 0.8 * 20.0

    # Extension functions for passing arguments with events.
    # Code taken from: https://dev.epicgames.com/community/snippets/d8k/fortnite-wrapping-subscribe-to-pass-additional-data-to-listeners.
    (Listenable : listenable(agent)).SubscribeAgent<public>(OutputFunc : tuple(agent, t)->void, ExtraData : t where t:type) : cancelable =
        Wrapper := wrapper_agent(t){ExtraData := ExtraData, OutputFunc := OutputFunc}
        Listenable.Subscribe(Wrapper.InputFunc)

    wrapper_agent(t : type) := class():
        ExtraData : t
        OutputFunc : tuple(agent, t) -> void
        InputFunc(Agent : agent):void = OutputFunc(Agent, ExtraData)

    (Listenable : listenable(widget_message)).SubscribeWidgetMessage<public>(OutputFunc : tuple(widget_message, t)->void, ExtraData : t where t:type) : cancelable =
        Wrapper := wrapper_widget_message(t){ExtraData := ExtraData, OutputFunc := OutputFunc}
        Listenable.Subscribe(Wrapper.InputFunc)

    wrapper_widget_message(t : type) := class():
        ExtraData : t
        OutputFunc : tuple(widget_message, t) -> void
        InputFunc(Message : widget_message):void = OutputFunc(Message, ExtraData)

    # Extension function for removing a key from a map.
    (Input:[t]t2 where t:subtype(comparable), t2:type).RemoveKey<public>(KeyToRemove:t)<decides><transacts>:[t]t2=
        var Output:[t]t2 = map{}
        for (Key -> Value : Input, Key <> KeyToRemove):
            set Output = ConcatenateMaps(Output, map{Key => Value})
        Output

    # Extension function for removing all matching elements from an array.
    (Input:[]t where t:type).RemoveAll<public>(Element:t, Compare(A:t, B:t)<decides><transacts>:void)<decides><transacts>:[]t=
        var Output:[]t = array{}
        for(InputElement : Input):
            if (not Compare[InputElement, Element]):
                set Output += array{InputElement}

        Output

    # Functions for localizing text.
    PlainText<public><localizes>(Text:string):message = "{Text}"

    CountText<public><localizes>(Count:int):message = "{Count}"

    LevelText<public><localizes>(Level:int, MaxLevel:int):message = "Level {Level} / {MaxLevel}"

    PlayerText<public><localizes>(PrefixText:string, Player:player, SuffixText:string):message = "{PrefixText}{Player}{SuffixText}"


    # Function for creating a string from a positive number by padding it with a character. 
    PadNumber<public>(PositiveNumber:int, PadToLength:int, Character:char)<transacts>:[]char=
        var Result : []char = "{PositiveNumber}"

        if (Result.Length < PadToLength):
            PadCount := PadToLength - Result.Length
            for(Count := 1..PadCount):
                set Result = array{Character} + Result

        Result

    # Function for rounding float to a certain positive number of decimals.
    # Code taken from: https://forums.unrealengine.com/t/how-to-round-float-to-x-decimal-places/821189/4
    (Input:float).ToString<public>(Decimals:int)<transacts>:string=
        Multiplier := Pow(10.0, Decimals * 1.0)
        if:
            RoundedValue := (Round[Input * Multiplier] * 1.0) / Multiplier
            BeforeDecimal := Floor[RoundedValue]
            AfterDecimal := Abs(Round[(RoundedValue - BeforeDecimal * 1.0) * Multiplier])
            var AfterDecimalString:string = ToString(AfterDecimal)

            for(X := 0..Decimals-AfterDecimalString.Length-1):
                set AfterDecimalString = "0" + AfterDecimalString
        then:
            "{BeforeDecimal}.{AfterDecimalString}"
        else:
            ToString(Input)

    # Function for parsing an integer from a string.
    ParseInt<public>(String : string)<decides><transacts>:int=
        String.Length > 0

        var Result : int = 0
        var Digit : int = 1
        for(Index := 0..String.Length-1):
            CharIndex := String.Length-1 - Index
            Char := String[CharIndex]
            case(Char):
                '-' => 
                    set Result *= -1
                '0' =>
                    set Digit *= 10
                '1' =>
                    set Result += 1 * Digit
                    set Digit *= 10
                '2' =>
                    set Result += 2 * Digit
                    set Digit *= 10
                '3' =>
                    set Result += 3 * Digit
                    set Digit *= 10
                '4' =>
                    set Result += 4 * Digit
                    set Digit *= 10
                '5' =>
                    set Result += 5 * Digit
                    set Digit *= 10
                '6' =>
                    set Result += 6 * Digit
                    set Digit *= 10
                '7' =>
                    set Result += 7 * Digit
                    set Digit *= 10
                '8' =>
                    set Result += 8 * Digit
                    set Digit *= 10
                '9' =>
                    set Result += 9 * Digit
                    set Digit *= 10
                '.' =>
                ',' =>
                _ => false?
        Result

    # Function for making a creative_prop shake.
    (Prop:creative_prop).Shake<public>(MaxPositionOffset:float, MaxRotationAngle:float, Count:int, Duration:float)<suspends>:void=
        Prop.Shake(vector3{X:=MaxPositionOffset, Y:=MaxPositionOffset, Z:=MaxPositionOffset}, vector3{X:=MaxRotationAngle, Y:=MaxRotationAngle, Z:=MaxRotationAngle}, Count, Duration)

    # Function for making a creative_prop shake.
    # The max offset and angles are specified in the prop's local space.
    (Prop:creative_prop).Shake<public>(MaxPositionOffset:vector3, MaxRotationYawPitchRollAngles:vector3, Count:int, Duration:float)<suspends>:void=
        if:
            AnimationController := Prop.GetAnimationController[]
        then:
            TimePerShake := Duration / (1.0 * Count)
            var Keyframes : []keyframe_delta = array{}
            Transform := Prop.GetTransform()
            StartPosition := Transform.Translation
            StartRotation := Transform.Rotation
            var PreviousPosition:vector3 = StartPosition
            var PreviousRotation:rotation = StartRotation
            for(Step := 1..Count):
                CurrentAmount := 1.0 - (1.0 * Step) / (1.0 * Count)
                CurrentPositionOffset := 
                    StartRotation.GetLocalForward() * GetRandomFloat(-CurrentAmount, CurrentAmount) * MaxPositionOffset.X +
                    StartRotation.GetLocalRight() * GetRandomFloat(-CurrentAmount, CurrentAmount) * MaxPositionOffset.Y +
                    StartRotation.GetLocalUp() * GetRandomFloat(-CurrentAmount, CurrentAmount) * MaxPositionOffset.Z
                CurrentYaw := GetRandomFloat(-CurrentAmount, CurrentAmount) * MaxRotationYawPitchRollAngles.X
                CurrentPitch := GetRandomFloat(-CurrentAmount, CurrentAmount) * MaxRotationYawPitchRollAngles.Y
                CurrentRoll := GetRandomFloat(-CurrentAmount, CurrentAmount) * MaxRotationYawPitchRollAngles.Z
                CurrentRotationAngle := MakeRotationFromYawPitchRollDegrees(CurrentYaw, CurrentPitch, CurrentRoll)
                CurrentRotation := CurrentRotationAngle.RotateBy(StartRotation)
                CurrentPosition := StartPosition + CurrentPositionOffset
                Keyframe := keyframe_delta:
                    DeltaLocation := CurrentPosition - PreviousPosition
                    DeltaRotation := MakeShortestRotationBetween(PreviousRotation, CurrentRotation)
                    Time := TimePerShake
                    Interpolation := InterpolationTypes.EaseInOut
                set Keyframes += array{Keyframe}
                set PreviousPosition = CurrentPosition
                set PreviousRotation = CurrentRotation
            AnimationController.SetAnimation(Keyframes, ?Mode := animation_mode.OneShot)
            AnimationController.Play()
            Sleep(Duration)

Comments

    Sign in to vote, comment, or suggest an edit. Sign in
    📄
    Source
    Epic Games

    © Epic Games. From an official Epic Games starter project / UEFN sample, shown here as reference for study with a link to Epic's docs. All rights remain with Epic Games — this is not Verse Island original work. Terms ↗

    View original Sources & licensing
    Request removal
    Tags
    epic-sample epic reference utility module generics localization
    Verse code
    Not yet compile-verified
    Sign in to download .verse

    Copy-paste the code above is always free.

    Keep exploring
    More in Verse Language · 73 of 106
    Prev
    santas toy factory upgrade config
    Next
    coltonkeeley projectost deprecated lottery wheel
    Related topics
    • Lego Santas Toy Factory In Unreal Editor For Fortnite Tutorials
    • Unreal Editor For Fortnite Starter Templates Tutorials
    • Playtesting Your Island In Unreal Editor For Fortnite Publishing
    • Playtesting Your Island Unreal Editor For Fortnite Publishing
    • fortniteitemcategories Items

    Related

    Open in graph →

    Related topics

    • Lego Santas Toy Factory In Unreal Editor For Fortnite
    • Unreal Editor For Fortnite Starter Templates
    • Playtesting Your Island In Unreal Editor For Fortnite
    • Playtesting Your Island Unreal Editor For Fortnite
    • fortniteitemcategories
    VerseIsland · an archipelago of Verse & UEFN knowledge
    🗺️ Island atlas Learn Guides History About & Press Sources & Licensing Status

    Not affiliated with Epic Games. Fortnite, UEFN, Unreal Engine, and Verse are trademarks of Epic Games, Inc. Content is attributed to its source — see Sources & Licensing.

    🦜

    Scout · your island guide

    The Isle of Verse