Knownlocations
Overview
This component manages a collection of named 3D world positions (Vector3) associated with an entity. It provides functionality to remember (store), retrieve, forget, serialize, and deserialize these locations—making it particularly useful for saving and loading persistent world landmarks or waypoints. It integrates with the game’s save/load system via OnSave and OnLoad methods.
Dependencies & Tags
None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
locations | table | {} | A dictionary mapping location names (strings) to Vector3 position values. |
inst | Entity | passed to constructor | Reference to the entity this component is attached to. |
Main Functions
RememberLocation(name, pos, dont_overwrite)
- Description: Stores a named position in the
locationstable. Ifdont_overwriteistrue, the position is only stored if the name does not already exist. Includes validation to detect invalid (NaN/Inf) coordinates and logs an error if found. - Parameters:
name(string): The identifier for the location.pos(Vector3): The 3D world position to store.dont_overwrite(boolean, optional): Iftrue, prevents overwriting an existing entry for the samename.
GetLocation(name)
- Description: Returns the stored
Vector3position for a given location name, ornilif not found. - Parameters:
name(string): The identifier of the location to retrieve.
ForgetLocation(name)
- Description: Removes a named location from the
locationstable. - Parameters:
name(string): The identifier of the location to remove.
SerializeLocations()
- Description: Converts the internal
locationstable into a serializable array of tables, each containingname,x,y, andz. - Parameters: None.
- Returns:
table?— A list of location records, ornilif no locations exist.
DeserializeLocations(data)
- Description: Restores locations from serialized data by calling
RememberLocationfor each entry. - Parameters:
data(table): An array of location records (as returned bySerializeLocations).
OnSave()
- Description: Serializes and returns the stored locations for saving to disk. Used by the save system.
- Parameters: None.
- Returns:
table?— A table of the form{ locations = serialized_data }, ornilif no locations exist.
OnLoad(data)
- Description: Loads previously saved location data and restores them. Used by the load system.
- Parameters:
data(table): Save data containingdata.locations, if any.
GetDebugString()
- Description: Returns a string listing all known location names and their positions, primarily for debugging display (e.g., via debugger UI). Includes commented-out visualization logic.
- Parameters: None.
- Returns:
string— A space-separated string of"name: position"entries.
Events & Listeners
None.