Skip to content

docs: add script systems docs #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Modifying Script Contexts](./Summary/customizing-script-contexts.md)
- [Shared Contexts](./Summary/sharing-contexts-between-scripts.md)
- [Script ID Mapping](./Summary/script-id-mapping.md)
- [Script Systems](./ScriptSystems/introduction.md)

# Scripting Reference

Expand Down
56 changes: 56 additions & 0 deletions docs/src/ScriptSystems/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Script Systems

<div class="warning">
Script systems are an experimental feature
</div>

It's possible within BMS to inject new systems from scripts themselves, although the support is currently limited.

Systems introduced by scripts cannot run in parallel to other systems, but can be freely inserted between any other rust system (not script systems at the moment) and into any schedule.


## Schedules

Bevy doesn't support reflecting schedules, so BMS rolls it's own schedule registry resource: `AppScheduleRegistry`, which can be used to add any custom schedules you want to interact with. The default Bevy schedules will be pre-populated for you.

Once you've registered your schedule you will be able to interact with it in scripts like below:

```lua
local update_schedule = world.get_schedule_by_name("Update")
local systems = update:systems()
local system_with_name = update:get_system_by_name("my_system")
```

## Inserting Systems

To insert a system you will need to use the `system_builder` global function like below:

```lua
local system = system_builder("my_system", script_id)
:after(some_Other_system)
:before(another_system)
```

This will let you call `world.add_system` like so:

```lua
world.add_system(update_schedule,system)
```

<div class="warning">

If your event handler running the script is running in a certain schedule, that schedule will be temporarilly removed by Bevy. Meaning you won't be able to modify it from within the script in-flight.

</div>

## Dynamic system

The system injected will be similar to an event handler, however it will only trigger the specified script, and without any entity, in the above example you'd see the following lua callback:

```lua
function my_system()
print("I am a dynamic system")
end
```

get triggered every update.
3 changes: 2 additions & 1 deletion docs/src/Summary/running-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

Once you have scripts discovered and loaded, you'll want to run them.

At the moment BMS supports two methods of making scripts runnable:
At the moment BMS supports three methods of making scripts runnable:
- Attaching them to entities via `ScriptComponent`'s
- Adding static scripts
- Creating dynamic systems ⚗️ (see [the script systems section](../ScriptSystems/introduction.md))

And then sending script event's which trigger callbacks on the scripts.

Expand Down
Loading