Skip to content

Commit bc65183

Browse files
committed
Added custom_settings examples
1 parent b746d1c commit bc65183

3 files changed

Lines changed: 71 additions & 1 deletion

File tree

docs/core-concepts/packages/packages-guide.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ GameModes can define Custom Settings in the `[custom_settings]` section to be se
153153

154154
The values defined can be accessed through the method <MethodReference type="StaticClass" class_name="Server" method_name="GetCustomSettings" show_class_name />.
155155

156+
Each setting is declared as `key = { ... }`, where the table describes how it should be displayed and validated in the New Game screen:
157+
158+
| Property | Type | Description |
159+
| :--- | :--- | :--- |
160+
| **`label`** | `string` | Friendly name displayed for this setting |
161+
| **`type`** | `string` | One of the [types](#list-of-types) below |
162+
| **`description`** | `string` | Help text displayed alongside the setting |
163+
| **`default`** | `boolean`\|`integer`\|`floating`\|`string` | Default value, must match the setting `type` |
164+
| **`options`** | `string[]` | Only used by the `select` type: the list of values shown in the dropdown |
165+
156166
#### List of Types {/* #list-of-types */}
157167

158168
| Type | Description |
@@ -163,6 +173,31 @@ The values defined can be accessed through the method <MethodReference type="Sta
163173
| `select` | List of string values displayed as a Dropdown |
164174
| `text` | Text Box |
165175

176+
#### Usage Example {/* #custom-settings-usage-example */}
177+
178+
```toml
179+
[custom_settings]
180+
max_props = { label = "Max Props", type = "integer", description = "maximum amount of props players can spawn", default = 1000 }
181+
enable_pvp = { label = "Enable PVP", type = "boolean", description = "whether to enable PVP or not", default = true }
182+
welcome_message = { label = "Welcome Message", type = "text", description = "message shown to players when they join", default = "have fun!" }
183+
game_mode = { label = "Game Mode", type = "select", description = "which ruleset to use", default = "Classic", options = [ "Classic", "Hardcore", "Free for All" ] }
184+
```
185+
186+
These are then exposed to every Package through <MethodReference type="StaticClass" class_name="Server" method_name="GetCustomSettings" show_class_name />, which returns a table keyed by the setting name and its raw value:
187+
188+
```lua
189+
local settings = Server.GetCustomSettings()
190+
191+
Console.Log(settings.max_props) -- 1000
192+
Console.Log(settings.game_mode) -- "Classic"
193+
```
194+
195+
They can also be overridden without touching `Package.toml`, either when creating a new game through the main menu, or by passing them directly on the command line, which takes precedence over both the New Game screen and `Package.toml` defaults:
196+
197+
```toml
198+
--custom_settings "max_props = 500, enable_pvp = false, game_mode = 'Hardcore'"
199+
```
200+
166201

167202
### Custom Data {/* #custom-data */}
168203

versioned_docs/version-latest/core-concepts/packages/packages-guide.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ GameModes can define Custom Settings in the `[custom_settings]` section to be se
153153

154154
The values defined can be accessed through the method <MethodReference type="StaticClass" class_name="Server" method_name="GetCustomSettings" show_class_name />.
155155

156+
Each setting is declared as `key = { ... }`, where the table describes how it should be displayed and validated in the New Game screen:
157+
158+
| Property | Type | Description |
159+
| :--- | :--- | :--- |
160+
| **`label`** | `string` | Friendly name displayed for this setting |
161+
| **`type`** | `string` | One of the [types](#list-of-types) below |
162+
| **`description`** | `string` | Help text displayed alongside the setting |
163+
| **`default`** | `boolean`\|`integer`\|`floating`\|`string` | Default value, must match the setting `type` |
164+
| **`options`** | `string[]` | Only used by the `select` type: the list of values shown in the dropdown |
165+
156166
#### List of Types {/* #list-of-types */}
157167

158168
| Type | Description |
@@ -163,6 +173,31 @@ The values defined can be accessed through the method <MethodReference type="Sta
163173
| `select` | List of string values displayed as a Dropdown |
164174
| `text` | Text Box |
165175

176+
#### Usage Example {/* #custom-settings-usage-example */}
177+
178+
```toml
179+
[custom_settings]
180+
max_props = { label = "Max Props", type = "integer", description = "maximum amount of props players can spawn", default = 1000 }
181+
enable_pvp = { label = "Enable PVP", type = "boolean", description = "whether to enable PVP or not", default = true }
182+
welcome_message = { label = "Welcome Message", type = "text", description = "message shown to players when they join", default = "have fun!" }
183+
game_mode = { label = "Game Mode", type = "select", description = "which ruleset to use", default = "Classic", options = [ "Classic", "Hardcore", "Free for All" ] }
184+
```
185+
186+
These are then exposed to every Package through <MethodReference type="StaticClass" class_name="Server" method_name="GetCustomSettings" show_class_name />, which returns a table keyed by the setting name and its raw value:
187+
188+
```lua
189+
local settings = Server.GetCustomSettings()
190+
191+
Console.Log(settings.max_props) -- 1000
192+
Console.Log(settings.game_mode) -- "Classic"
193+
```
194+
195+
They can also be overridden without touching `Package.toml`, either when creating a new game through the main menu, or by passing them directly on the command line, which takes precedence over both the New Game screen and `Package.toml` defaults:
196+
197+
```
198+
--custom_settings "max_props = 500, enable_pvp = false, game_mode = 'Hardcore'"
199+
```
200+
166201

167202
### Custom Data {/* #custom-data */}
168203

0 commit comments

Comments
 (0)