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)| Parameter | Description |
|---|---|
name | Display name for this list |
parent | Parent object passed to the object constructor |
objectConstructor | function(parent, name, forceId) → object with .id and .sortOrder |
Methods (C)
Core Operations
| Method | Signature | Description |
|---|---|---|
create | (name, forceId?) → object | Creates 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
| Method | Signature | Description |
|---|---|---|
buildNamesDir | () | Populates byName table for name-based lookup |
Debug
| Method | Signature | Description |
|---|---|---|
drawDebug | (drawMode) | Calls drawDebug on each object |
Serialization
| Method | Signature | Description |
|---|---|---|
onSerialize | (parent?) → table | Serializes all non-procedural objects |
onDeserialized | (data, oldIdMap) | Deserializes and rebuilds, populating oldIdMap |
Overridable Callbacks
| Callback | Description |
|---|---|
postClear | Called after clear() |
postCreate | Called after create() with the new object |
postRemove | Called 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
- Objects are created via the provided constructor and stored by ID
- After every insert/remove,
sort()rebuilds the sorted array - Sort order is based on
sortOrderproperty (renumbered sequentially after each sort) move()swaps two adjacent objects' sort positions- Procedural objects (
isProcedural = true) are excluded from serialization - 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.