Sites Custom Fields
Class for managing typed custom fields and tags on sites objects (locations, zones, parking spots). Supports `string`, `number`, and `vec3` field types plus a tag set.
Class for managing typed custom fields and tags on sites objects (locations, zones, parking spots). Supports string, number, and vec3 field types plus a tag set.
Constructor
local CustomFields = require('gameplay/sites/customFields')
local fields = CustomFields()Methods
| Method | Signature | Returns | Description |
|---|---|---|---|
add | (name, type, value) | bool | Add a new field (fails if exists) |
remove | (name) | bool | Remove a field by name |
set | (name, value) | bool | Update existing field value |
get | (name) | value, type, found | Get field value, type, and existence flag |
has | (name) | bool | Check if field exists |
addTag | (tag) | bool | Add a tag (fails if duplicate) |
removeTag | (tag) | bool | Remove tag by string or index |
onSerialize | () | table | Serialize fields and tags |
onDeserialized | (data) | nil | Restore from serialized data |
Internals
names: Ordered array of field namestypes: Map ofname → type("string","number","vec3")values: Map ofname → valuetags: Set oftag → 1sortedTags: Sorted array of tag strings (rebuilt on change)
How It Works
Fields are typed key-value pairs with insertion-order tracking. Tags are an unordered set that auto-sorts when modified. Serialization converts vec3 values to tables.
local fields = CustomFields()
-- Add typed fields
fields:add("speed", "number", 120)
fields:add("label", "string", "Start Line")
fields:add("offset", "vec3", vec3(1, 2, 3))
-- Query
local val, typ, found = fields:get("speed") -- 120, "number", true
-- Tags
fields:addTag("parking")
fields:addTag("accessible")
-- fields.sortedTags = {"accessible", "parking"}
-- Serialize for JSON
local data = fields:onSerialize()
-- { names={"speed","label","offset"}, types={...}, values={...}, tags={"accessible","parking"} }Notes
set("tags", ...)triggersupdateTags()- but tags are normally managed viaaddTag/removeTagremoveTagaccepts either a string or numeric index intosortedTags- Used by
location,zone, andparkingSpotclasses
| Function | Signature | Returns | Description |
|---|---|---|---|
M.init | () | nil | init |
See Also
- Sites Location - Related reference
- Sites Parking Spot - Related reference
- Sites Container - Related reference
- Gameplay Systems Guide - Guide
Gameplay Route
Core route class for navigation pathfinding. Creates a path between positions using the map graph, tracks vehicle position along it, and auto-recalculates when off-route.
Sites Location
Class representing a named point location within the sites system. Has a position, radius, color, and custom fields. Used for marking points of interest within zones.