forked from mucklet/mucklet-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.ts
More file actions
60 lines (57 loc) · 2.05 KB
/
hello_world.ts
File metadata and controls
60 lines (57 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* A bare bone script that displays the text "Hello, world!" when activated.
*/
/**
* onActivate is called each time a script is activated or updated. It is
* primarily used to call `Room.listen` or `Script.listen`, to have the script
* listening for events or messages.
*
* When a script is updated, previous listeners (`Room.listen` or
* `Script.listen`) or scheduled posts (`Script.post` with delay), will be
* removed before onActivate() is called on the new script version.
*
* Not required. Can be remove if not used.
*/
export function onActivate(): void {
Room.describe("Hello, world!");
}
/**
* onRoomEvent is called when an event occurs in the room, such as a 'say',
* 'arrive', or 'sleep'. It requires that `Room.listen()` has been called
* earlier, usually in the onActivate() function.
*
* Not required. Can be remove if not used.
*
* @example
* Check the event type and decode the event:
* ```
* export function onRoomEvent(addr: string, ev: string): void {
* const eventType = Event.getType(ev);
* if (eventType == 'say') {
* const say = JSON.parse<Event.Say>(ev);
* // Handle the say event
* }
* }
* ```
*
* @param addr - Address of this script instance receiving the event.
* @param ev - Event encoded as a json string.
*/
export function onRoomEvent(addr: string, ev: string): void {
// Handle the json encoded event
}
/**
* onMessage is called when another script sends a message to this script, using
* Script.post(). It requires that `Script.listen()` has been called earlier,
* usually in the onActivate() function.
*
* Not required. Can be remove if not used.
*
* @param addr - Address of this script instance receiving the message.
* @param topic - Topic of the message. Determined by the sender.
* @param data - JSON encoded data of the message or null. Determined by the sender.
* @param sender - Address of the sending script instance.
*/
export function onMessage(addr: string, topic: string, data: string | null, sender: string): void {
// Handle the message and the JSON encoded data
}