RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Gameplay AchievementGameplay CityDiscoverForce FieldGarage ModeMarker InteractionParking SystemGameplay Playmode MarkersGameplay PoliceGameplay RallyGameplay Rally LoopGameplay Raw POIsGameplay Skidpad TestSpeed Trap LeaderboardsSpeed Traps and CamerasGameplay StatisticsTaxi Ride SystemTraffic SystemVehicle PerformanceWalking
Crash DetectionDamage AssessmentGround ContactSorted List

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE Extensionsgameplayutil

Sorted List

Reference for `gameplay_util_sortedList`, a generic container that manages a list of named, ID-bearing objects with sorted ordering, name-based lookup, and serialization support.

Reference for gameplay_util_sortedList, a generic container that manages a list of named, ID-bearing objects with sorted ordering, name-based lookup, and serialization support.


Constructor

local list = require('gameplay/util/sortedList')(name, parent, objectConstructor)
ParameterDescription
nameDisplay name for this list
parentParent object passed to the object constructor
objectConstructorfunction(parent, name, forceId) → object with .id and .sortOrder

Methods (C)

Core Operations

MethodSignatureDescription
create(name, forceId?) → objectCreates a new object, inserts and sorts
remove(obj or id)Removes an object by reference or ID
clear()Removes all objects
sort()Rebuilds sorted array and renumbers sortOrder
move(id, dir)Swaps sort position with neighbor (dir = +1 or -1)

Lookup

MethodSignatureDescription
buildNamesDir()Populates byName table for name-based lookup

Debug

MethodSignatureDescription
drawDebug(drawMode)Calls drawDebug on each object

Serialization

MethodSignatureDescription
onSerialize(parent?) → tableSerializes all non-procedural objects
onDeserialized(data, oldIdMap)Deserializes and rebuilds, populating oldIdMap

Overridable Callbacks

CallbackDescription
postClearCalled after clear()
postCreateCalled after create() with the new object
postRemoveCalled after remove()

Data Structures

list.objects (table)

ID-keyed table of all objects. Has a metatable that returns a sentinel {name="Missing!", missing=true, id=-1} for missing keys.

list.sorted (array)

Objects sorted by sortOrder. Rebuilt on every mutation.

list.byName (table)

Name-keyed lookup table. Only populated when buildNamesDir() is called explicitly. First object with a given name wins.


How It Works

  1. Objects are created via the provided constructor and stored by ID
  2. After every insert/remove, sort() rebuilds the sorted array
  3. Sort order is based on sortOrder property (renumbered sequentially after each sort)
  4. move() swaps two adjacent objects' sort positions
  5. Procedural objects (isProcedural = true) are excluded from serialization
  6. Deserialization recreates objects, tracking old→new ID mappings via oldIdMap

Usage Example

local sortedList = require('gameplay/util/sortedList')

-- Create a list with a simple constructor
local myList = sortedList("myObjects", parentObj, function(parent, name, forceId)
  local id = forceId or getNextId()
  return {id = id, name = name, sortOrder = id, parent = parent}
end)

-- Add objects
local obj1 = myList:create("First")
local obj2 = myList:create("Second")

-- Reorder
myList:move(obj1.id, 1)  -- move down

-- Lookup by name
myList:buildNamesDir()
local found = myList.byName["First"]

-- Iterate in order
for _, obj in ipairs(myList.sorted) do
  log("I", "", obj.name)
end

-- Serialize
local data = myList:onSerialize()

See Also

  • gameplay/util/crashDetection - Vehicle Crash Detection System - Related reference
  • gameplay/util/damageAssessment - Vehicle Damage Location Assessment - Related reference
  • gameplay/util/groundContact - Ground Contact Detection - Related reference
  • Gameplay Systems Guide - Guide

Ground Contact

Reference for `gameplay_util_groundContact`, a simple utility that checks whether a vehicle is resting on its wheels (right-side-up and touching the ground).

Remote Control HTTP

Provides a simple HTTP server that exposes REST-style endpoints for remote vehicle control. Registers a virtual input device and emits axis/button events over HTTP.

On this page

ConstructorMethods (C)Core OperationsLookupDebugSerializationOverridable CallbacksData Structureslist.objects (table)list.sorted (array)list.byName (table)How It WorksUsage ExampleSee Also