Worldsettings
Overview
The worldsettings component provides a simple key-value store for global world settings in the Entity Component System. It allows setting and retrieving configuration values (e.g., difficulty modes, world generation flags) that persist across the game session and can be updated dynamically via network events.
Dependencies & Tags
- Component dependency: None (this component does not require or verify other components on
inst). - Tags: None added or removed.
- Event listener: Registers a global listener for the
"ms_setworldsetting"event (handled byOnSetWorldSetting).
Properties
The constructor initializes one private property:
| Property | Type | Default Value | Description |
|---|---|---|---|
settings | table | {} | Internal dictionary storing world setting keys (strings) mapped to values of any type. |
Note: No public instance properties are exposed directly; access is provided solely through
GetSettingandSetSetting.
Main Functions
GetSetting(setting)
- Description: Retrieves the current value of a world setting by its name.
- Parameters:
setting(string): The key/name of the setting to look up.
SetSetting(setting, value)
- Description: Sets or updates a world setting to the specified value.
- Parameters:
setting(string): The key/name of the setting to update.value(any): The value to assign; can be any Lua type (e.g.,string,number,boolean,table).
Events & Listeners
- Listens for
"ms_setworldsetting": A multiplayer-safe event (indicated by the"ms_"prefix) that carries adatatable containingdata.settinganddata.value. When received, it callsSetSettingon the localworldsettingscomponent instance if present.
This event listener ensures that setting updates initiated on the master client are propagated and applied consistently on all connected clients and the server.