mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-05-18 19:42:07 +00:00
Add documentation for the setting_changed event (#2405)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
---
|
||||
module: [kind=event] setting_changed
|
||||
see: settings
|
||||
---
|
||||
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2026 The CC: Tweaked Developers
|
||||
|
||||
SPDX-License-Identifier: MPL-2.0
|
||||
-->
|
||||
|
||||
The [`setting_changed`] event is fired when a setting is modified with the [`settings`] API.
|
||||
|
||||
## Return Values
|
||||
1. [`string`]: The event name.
|
||||
2. [`string`]: The name of the setting that was changed.
|
||||
3. [`any`]: The value the setting was set to.
|
||||
4. [`any`]: The previous value of the setting.
|
||||
|
||||
## Example
|
||||
[Update a setting][`settings.set`], and then wait for the corresponding
|
||||
`setting_changed` event.
|
||||
|
||||
```lua
|
||||
settings.set("my.setting", 123)
|
||||
print(os.pullEvent("setting_changed"))
|
||||
```
|
||||
@@ -8,12 +8,20 @@ When a computer starts, it reads the current value of settings from the
|
||||
`/.settings` file. These values then may be [read][`settings.get`] or
|
||||
[modified][`settings.set`].
|
||||
|
||||
|
||||
Any modifications to a settings, either from loading a file ([`settings.load`])
|
||||
or directly setting it ([`settings.set`], [`settings.unset`]) will queue a
|
||||
[`setting_changed`] event. This may be listened to by programs to reload
|
||||
settings while running.
|
||||
|
||||
> [!WARNING]
|
||||
> Calling [`settings.set`] does _not_ update the settings file by default. You
|
||||
> _must_ call [`settings.save`] to persist values.
|
||||
|
||||
@module settings
|
||||
@see setting_changed
|
||||
@since 1.78
|
||||
@changed 1.87.0 [`setting_changed`] event is now queued when settings are changed.
|
||||
@usage Define an basic setting `123` and read its value.
|
||||
|
||||
settings.define("my.setting", {
|
||||
|
||||
Reference in New Issue
Block a user