Skip to content

Commit 70598ae

Browse files
committed
docs: add script systems docs
1 parent 3374206 commit 70598ae

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Script Systems
2+
3+
<div class="warning">
4+
Script systems are an experimental feature
5+
</div>
6+
7+
It's possible within BMS to inject new systems from scripts themselves, although the support is currently limited.
8+
9+
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.
10+
11+
12+
## Schedules
13+
14+
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.
15+
16+
Once you've registered your schedule you will be able to interact with it in scripts like below:
17+
18+
```lua
19+
local update_schedule = world.get_schedule_by_name("Update")
20+
local systems = update:systems()
21+
local system_with_name = update:get_system_by_name("my_system")
22+
```
23+
24+
## Inserting Systems
25+
26+
To insert a system wou will need to use the `system_builder` global function like below:
27+
28+
```lua
29+
local system = system_builder("my_system", script_id)
30+
:after(some_Other_system)
31+
:before(another_system)
32+
```
33+
34+
This will let you call `world.add_system` like so:
35+
36+
```lua
37+
world.add_system(update_schedule,system)
38+
```
39+
40+
<div class="warning">
41+
42+
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.
43+
44+
</div>
45+
46+
## Dynamic system
47+
48+
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:
49+
50+
```lua
51+
function my_system()
52+
print("I am a dynamic system")
53+
end
54+
```
55+
56+
get triggered every update.

docs/src/Summary/running-scripts.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

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

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

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

0 commit comments

Comments
 (0)