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 › Assets
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

Quicksort Algorithm Implementation

Module — 2 files
These files compile together (same module folder).
file_1.verse
# A divide-and-conquer sorting algorithm that divides an array into subarrays by selecting a pivot element.
# Elements less than the pivot are sorted to left of the pivot, and elements greater than the pivot are sorted to the right.
# The algorithm then divides into subarrays on either side of the pivot, and continues the process, selecting a new pivot each time.
# At the end each of the sorted subarrays is merged together to get a fully sorted array.
# This is a recursive implementation, where the function calls itself to quick sort the divided arrays.
# The base case (the condition to stop the recursion) is the array has only one element.
# This implementation always selects for the rightmost element as the initial pivot. 
# This is a generic implementation using parametric types, so you can provide your own type and your own comparison function as arguments.
QuickSort<public>(Array:[]t, Compare(L:t, R:t)<decides><transacts>:t where t:type)<transacts>:[]t=
    QuickSortAtPivot(Array, 0, Array.Length - 1, Compare)

QuickSortAtPivot<public>(Array:[]t, LowIndex:int, HighIndex:int, Compare(L:t, R:t)<decides><transacts>:t where t:type)<transacts>:[]t=
    if:
        # Check if the length of the array is greater than one. If not we've
        # reached the base case and should stop recursion.
        LowIndex < HighIndex
        # Sort the elements in the array by using the HighIndex (rightmost) element
        # as the Pivot. Return the index of the Pivot after sorting along with the sorted array.
        PartitionTuple := Partition(Array, LowIndex, HighIndex, Compare)
        PivotIndex := PartitionTuple(0)
        SortedArray := PartitionTuple(1)
        # Split the array into subarrays left and right of the pivot value.
        LeftHalf := SortedArray.Slice[LowIndex, PivotIndex]
        PivotVal := array{SortedArray[PivotIndex]}
        RightHalf := SortedArray.Slice[PivotIndex + 1]
    then:
        # Recursively sort the Left and Right subarrays.
        LeftArray := QuickSortAtPivot(LeftHalf, LowIndex, PivotIndex - 1, Compare)
        RightArray := QuickSortAtPivot(RightHalf, 0, RightHalf.Length - 1, Compare)

        # Rejoin the the Left and Right subarrays with the Pivot value.
        LeftArray + PivotVal + RightArray
    else:
        Array

# A helper function for QuickSort that swaps elements by comparing them to the element at the Pivot. Elements less than the Pivot
# are sorted to the left, and elements greater than the pivot are sorted to the right.
# This algorithm uses two index values, SmallerIndex and LargerIndex. The LargerIndex is the index of the element to
# compare to the Pivot value, and the SmallerIndex is the index of the element to swap with the Pivot when the algorithm completes.    
Partition(Array:[]t, LowIndex:int, HighIndex:int, Compare(L:t, R:t)<decides><transacts>:t where t:type)<transacts>:tuple(int, []t)=
    # Index of the smaller element, 
    # right-side position of the pivot.
    var SmallerIndex:int := LowIndex - 1
    var TempArray:[]t = Array
    if:
        # The Pivot, the item at the HighIndex (rightmost) index in the array.
        var Pivot:t := TempArray[HighIndex]
    then:
        # The index of the element to compare against the Pivot.
        var LargerIndex:int := LowIndex
        loop:
            if:
                # Check if we've reached the end of the array.
                LargerIndex > HighIndex
            then:
                break
            else:
                if:
                    # The element at LargerIndex, which will be compared to the Pivot value.
                    ComparedVal := TempArray[LargerIndex]
                    
                    # If the element at LargerIndex is less than the pivot value,
                    # swap the elements at SmallerIndex and LargerIndex
                    Compare[ComparedVal, Pivot]
                then:
                    set SmallerIndex = SmallerIndex + 1
                    if:
                        StoredVal := TempArray[SmallerIndex]
                        # Swap the elements at SmallerIndex and LargerIndex.
                        Swap1 := TempArray.ReplaceElement[SmallerIndex, ComparedVal]
                        Swap2 := Swap1.ReplaceElement[LargerIndex, StoredVal]
                        set TempArray = Swap2
                    else:
                        Test.ProjectLog("Unable to swap elements at smaller and larger indices during sorting.")
            # Increment the LargerIndex each iteration of the loop.
            set LargerIndex = LargerIndex + 1  
        # Finally, swap the element at SmallerIndex with the element at the Pivot.
        if:
            set SmallerIndex = SmallerIndex + 1
            # Save a reference to the elements at SmallerIndex and HighIndex.
            StoredVal := TempArray[SmallerIndex]
            PivotVal := TempArray[HighIndex]
            # Swap the elements at SmallerIndex and HighIndex.
            Swap3 := TempArray.ReplaceElement[SmallerIndex, PivotVal]
            Swap4 := Swap3.ReplaceElement[HighIndex, StoredVal]
            set TempArray = Swap4
        else:
            Test.ProjectLog("Unable to swap the element at the smaller and high indices during sorting.")

    # Return the index of the new Pivot and the modified array.
    (SmallerIndex, TempArray)
test_sorting.verse
# This file contains tests for verifying the sorting algorithm behaves as expected.
# The tests also include profiling the code to see the performance of the algorithm.

using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
 
test_log_channel<public> := class(log_channel):
 
# A project-wide "Logger" to print messages from functions that are not in a class with a log.
# The non-Logger Print is <no_rollback>, so it can't be used in a <transacts> function.
ProjectLog<public>(Message:[]char, ?Level:log_level = log_level.Normal)<transacts>:void=
    Logger := log{Channel := test_log_channel}
    Logger.Print(Message, ?Level := Level)
 
# A Verse-authored creative device that can be placed in a level.
# Place in the level to run tests and profile code.
test_sorting := class(creative_device):
 
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void= 
        # Example arrays to use for the test.
        var ArrayLength:int = GetRandomInt(10, 100)
        Test1ExpectedIntArray:[]int = for (Count := 0..ArrayLength):
            Count
        Test1ActualIntArray:[]int = Shuffle(Test1ExpectedIntArray)
 
        set ArrayLength = GetRandomInt(10, 100)
        Test2ExpectedIntArray:[]int = for (Count := 0..ArrayLength):
            ArrayLength - Count
        Test2ActualIntArray:[]int = Shuffle(Test2ExpectedIntArray)
 
        Test3ExpectedIntArray:[]int = array{0, 1, 1, 2, 3, 3}
        Test3ActualIntArray:[]int = Shuffle(Test3ExpectedIntArray)
 
        set ArrayLength = GetRandomInt(10, 100)
        Test4ExpectedPlayerStats:[]player_stats = for (Count := 0..ArrayLength):
            player_stats:
                Wins := ArrayLength - Count
                RoundsPlayed := GetRandomInt(Count, Count * 30)
        Test4ActualPlayerStats:[]player_stats = Shuffle(Test4ExpectedPlayerStats)
 
        # Run the tests and report if they failed or succeeded.
        if:
            RunArrayTest["Integer array in order from smallest to largest", Test1ActualIntArray, Test1ExpectedIntArray, IsIntSmallerThan, IntArrayToString]
            RunArrayTest["Integer array in order from largest to smallest", Test2ActualIntArray, Test2ExpectedIntArray, IsIntGreaterThan, IntArrayToString]
            RunArrayTest["Integer array in order from smallest to largest with repeats", Test3ActualIntArray, Test3ExpectedIntArray, IsIntSmallerThan, IntArrayToString]
            RunArrayTest["Player stats array in order from largest # wins to smallest", Test4ActualPlayerStats, Test4ExpectedPlayerStats, IsWinsGreaterThan, PlayerStatsWinsArrayToString]
        then:
            ProjectLog("All tests passed.")
        else:
            ProjectLog("One or more tests failed.")
           
# Test function for sorting arrays and profiling the code.
RunArrayTest(Description:string, ActualArray:[]t, ExpectedArray:[]t, Compare(L:t, R:t)<decides><transacts>:t, ArrayToString(:[]t)<transacts>:string where t:subtype(comparable))<decides><transacts>:void=
    # Perform quick sort and profile the code.
    ResultArray := profile(Description):
        SortingAlgorithms.QuickSort(ActualArray, Compare)
 
    # Print out the Actual, Expected, and Result arrays for troubleshooting.
    ProjectLog("Actual: {ArrayToString(ActualArray)}")
    ProjectLog("Expected: {ArrayToString(ExpectedArray)}")
    ProjectLog("Result: {ArrayToString(ResultArray)}")
 
    # Verify the test passed and sorted the array as expected.
    for (Index -> Result : ResultArray, Expected := ExpectedArray[Index]):
        Result = Expected
 
# Helper function to convert an integer array to a string.
IntArrayToString(Array:[]int)<transacts>:string=
    var ConvertedToString:string = "["
   
    for(Index -> Element : Array):
        set ConvertedToString += "{Element}"
        if (Index < Array.Length - 1):
            set ConvertedToString += ", "
       
    set ConvertedToString += "]"

# Helper function to convert the player stats comparison values to a string.
PlayerStatsWinsArrayToString(Array:[]player_stats)<transacts>:string=
    var ConvertedToString:string = "["
   
    for(Index -> Element : Array):
        set ConvertedToString += "{Element.Wins}"
        if (Index < Array.Length - 1):
            set ConvertedToString += ", "
       
    set ConvertedToString += "]"
 
# Comparison function to use as argument for sorting integers from smallest to largest number.
IsIntSmallerThan(Left:int, Right:int)<decides><transacts>:int=
    Left < Right

# Comparison function to use as argument for sorting integers from largest to smallest number.
IsIntGreaterThan(Left:int, Right:int)<decides><transacts>:int=
    Left > Right
 
# An example class for testing sorting.
player_stats := class<unique>:
    Wins:int = 0
    RoundsPlayed:int = 0
 
# Comparison function to use as argument for sorting wins from smallest to largest.
IsWinsSmallerThan(Left:player_stats, Right:player_stats)<decides><transacts>:player_stats=
    Left.Wins < Right.Wins
    Left
 
# Comparison function to use as argument for sorting wins from largest to smallest.
IsWinsGreaterThan(Left:player_stats, Right:player_stats)<decides><transacts>:player_stats=
    Left.Wins > Right.Wins
    Left
Sign in to download module

Copy-paste each file above is always free.

Comments

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

    Created by a member of the Epic Games community. Rights remain with the original author, under Epic's community content terms. Terms ↗

    View original Sources & licensing
    Request removal
    Last updated Jun 23, 2026
    Verse module (2 files)
    Build failed · 3 errors

    Download the full module (zip) from the code panel above.

    Keep exploring
    More in Verse Language · 20 of 106
    Prev
    fortnite float to string with decimal places
    Next
    fortnite ensure onbegin execution order
    Related topics
    • Fortnite Merge Sort Verse Language
    • Sorting Algorithms In Verse Verse Language
    • Sorting Algorithms In Verse Verse Language
    • Fortnite Sort A Map With Key Value Verse Language
    • sortby Verse Language

    Related

    Open in graph →

    Related topics

    • Fortnite Merge Sort
    • Sorting Algorithms In Verse
    • Sorting Algorithms In Verse
    • Fortnite Sort A Map With Key Value
    • sortby
    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