Skip to content

Commit c42963a

Browse files
committed
add docs about callbacks
1 parent 0307fb9 commit c42963a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
- [ScriptTypeRegistration](./ScriptingReference/script-type-registration.md)
1818
- [ScriptQueryBuilder](./ScriptingReference/script-query-builder.md)
1919
- [ScriptQueryResult](./ScriptingReference/script-query-result.md)
20+
- [Core Callbacks](./ScriptingReference/core-callbacks.md)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Core Callbacks
2+
3+
On top of callbacks which are registered by your application, BMS provides a set of core callbacks which are always available.
4+
5+
The two core callbacks are:
6+
- `on_script_loaded`
7+
- `on_script_unloaded`
8+
9+
## `on_script_loaded`
10+
11+
This will be called right after a script has been loaded or reloaded. This is a good place to initialize your script. You should avoid placing a lot of logic into the global body of your script, and instead put it into this callback. Otherwise errors in the initialization will fail the loading of the script.
12+
13+
```lua
14+
print("you can also use this space, but it's not recommended")
15+
function on_script_loaded()
16+
print("Hello world")
17+
end
18+
```
19+
20+
## `on_script_unloaded`
21+
22+
This will be called right before a script is unloaded. This is a good place to clean up any resources that your script has allocated. Note this is not called when a script is reloaded, only when it is being removed from the system.
23+
24+
```lua
25+
function on_script_unloaded()
26+
print("Goodbye world")
27+
end
28+
```

0 commit comments

Comments
 (0)