You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/Summary/running-scripts.md
+15-4Lines changed: 15 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -13,28 +13,39 @@ Scripts can run logic either when loaded or when triggered by an event. For exam
13
13
14
14
```lua
15
15
print("hello from load time")
16
-
functionon_event()
16
+
functionon_event(arg1)
17
17
print("hello from event time")
18
+
print(arg1)
18
19
end
19
20
```
20
21
21
22
Will print "hello from load time" when the script is loaded, and "hello from event time" when the script receives an event targeting the `on_event` callback with a receiver list including this script or entity.
22
23
23
24
In order to trigger `on_event` you need to first define a label, then send an event containing the label:
24
25
```rust,ignore
26
+
27
+
#[derive(Reflect)]
28
+
pub struct MyReflectType;
29
+
25
30
// define the label, you can define as many as you like here
let my_reflect_payload = ReflectReference::new_allocated(MyReflectType, &mut allocator);
38
+
30
39
writer.send(ScriptCallbackEvent::new_for_all(
31
40
OnEvent,
32
-
vec![ScriptValue::Unit],
41
+
vec![my_reflect_payload.into()],
33
42
));
34
43
}
35
44
```
36
45
37
-
Note the second argument is the payload we are sending with the event, in this case we are sending an empty payload.
46
+
Note the second argument is the payload we are sending with the event, in this case we are sending an arbitrary reflect type `MyReflectType`. This can be any type you like, as long as it implements `Reflect`.
47
+
48
+
Other variants of the `ScriptValue` enum are available for sending different types of data, such as `ScriptValue::Integer` for primtive, types.
0 commit comments