scripting
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| scripting [2026/02/11 23:17] – created dooskington | scripting [2026/02/11 23:21] (current) – dooskington | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | # Server-side Lua scripting | + | ==== Server-side Lua scripting |
| - | This page documents the game-server Lua scripting system and how to bind scripts through | + | This page documents the game-server Lua scripting system and how to bind scripts through |
| Related pages: | Related pages: | ||
| - | - [[server: | + | * [[scripting/ |
| - | - [Lua API reference (Markdown)](./ | + | |
| - | ## Where scripts live | + | ==== Where scripts live ==== |
| - | - Script resources are loaded from `server/ | + | * Script resources are loaded from '' |
| - | - A script resource name is its path relative to `res/scripts` without the `.lua` extension. | + | |
| - | | + | |
| - | - Files under `res/ | + | |
| - | | + | |
| - | ## Script execution model | + | ==== Script execution model ==== |
| - | The `ScriptSystem` runs once per server tick and drains queued | + | The '' |
| Main execution paths: | Main execution paths: | ||
| - | - `ScriptComponent.on_init` on entity spawn. | + | * '' |
| - | - `ScriptComponent.on_hit` on `OnEntityAttackedEvent` for the target entity. | + | * '' |
| - | - Interaction, | + | |
| - | The global | + | The global |
| - | ## Using `ScriptComponent` | + | ==== Using ScriptComponent |
| - | Add a `[script]` table to an entity resource (`res/ | + | Add a '' |
| - | ```toml | + | < |
| [script] | [script] | ||
| on_init = " | on_init = " | ||
| on_hit = " | on_hit = " | ||
| - | ``` | + | </ |
| - | ### `on_init` | + | === on_init |
| - | - Runs when the entity is spawned. | + | * Runs when the entity is spawned. |
| - | - Context type: `DefaultScriptContextData` | + | |
| - | - `Context: | + | * '' |
| - | - `Context: | + | * '' |
| - | ### `on_hit` | + | === on_hit |
| - | - Runs when the entity is attacked. | + | * Runs when the entity is attacked. |
| - | - Context type: `OnEntityAttackedScriptContextData` | + | |
| - | - `Context: | + | * '' |
| - | - `Context: | + | * '' |
| - | - `Context: | + | * '' |
| - | - `Context: | + | * '' |
| - | ### Inline vs resource scripts | + | === Inline vs resource scripts |
| - | Both `on_init` and `on_hit` support two forms: | + | Both '' |
| - | 1. **Resource reference** (string ending in `.lua`): | + | - Resource reference (string ending in '' |
| - | | + | - The server looks up the resource and executes it. |
| - | 2. **Inline Lua source** (any other string): | + | |
| - | | + | - The string itself is executed as Lua code. |
| For maintainability, | For maintainability, | ||
| - | ## Script module (`include/`) usage | + | ==== Script module (include/) usage ==== |
| - | Modules under `res/ | + | Modules under '' |
| Example: | Example: | ||
| - | ```lua | + | < |
| local common = require(" | local common = require(" | ||
| local tutorial = require(" | local tutorial = require(" | ||
| local DamageType = require(" | local DamageType = require(" | ||
| - | ``` | + | </ |
| Useful built-in modules currently in the repo: | Useful built-in modules currently in the repo: | ||
| - | - `common` (helper wrappers, e.g. `common.open_modal`) | + | * '' |
| - | - `damage_type` (damage bit constants) | + | * '' |
| - | - `stat` (stat IDs) | + | * '' |
| - | - `tutorial` (tutorial constants/ | + | * '' |
| - | ## Resource validation | + | ==== Resource validation |
| On resource load/ | On resource load/ | ||
| - | For `ScriptComponent`, only values ending in `.lua` are validated as resource names. Missing resources are logged as validation errors. | + | For '' |
| - | ## Reload and iteration workflow | + | ==== Reload and iteration workflow |
| Recommended flow while developing scripts: | Recommended flow while developing scripts: | ||
| - | 1. Edit files in `res/scripts` or entity resources in `res/ents`. | + | - Edit files in '' |
| - | 2. Use `/ | + | |
| - | 3. Scripts under `include/` are reloaded and re-preloaded. | + | |
| - | 4. Trigger the entity behavior in-game. | + | |
| + | |||
| + | For quick one-off evaluation, developers can use ''/ | ||
| - | For quick one-off evaluation, devs can use `/lua [code]` which queues an ad-hoc script execution with default context. | ||
scripting.1770851867.txt.gz · Last modified: by dooskington
