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
@@ -21,27 +21,33 @@ This macro set allows Twine authors to create event programming without needing
21
21
<</event>>
22
22
```
23
23
24
-
This macro set can be used to add more interaction to your game; things like keyboard hotkeys, controls, clickable non-link elements, and more. Once registered, events are essentially permanent (though they can be removed via JavaScript and suppressed via code logic); therefore, **the best place to create events is your StoryInit special passage**. Note that the element the event is tied to does not need to be rendered (or currently on the page or in the passage) in order to attach an event to it.
24
+
This macro be used to handle events in your game; things like keyboard hotkeys, controls, clickable non-link elements, and more. Note that the element the event is tied to does not need to be rendered (or currently on the page or in the passage) in order to attach an event to it.
25
25
26
-
***type**: a valid jQuery event type. Some events that may be of interest:
26
+
This macro has three aliases: `<<on>>` set recurring event handlers, while `<<one>>` creates a single-use event handler. If you want the handler to run each and every time the event occurs, use `<<on>>`. If you want the event to occur only once, the next time the event occurs, use `<<one>>`.
27
+
28
+
> [!NOTE]
29
+
> The `<<event>>` macro exists as an alias for `<<on>>` for backwards-compatibility with code written for older version of this macro set. The `<<event>>` macro should be considered deprecated going forward.
30
+
31
+
***type**: a valid jQuery event type. You may include a namespace with a dot, e.g., `click.my-namespace`. Some events that may be of interest:
27
32
*`click`: fires when an element is clicked on.
28
33
*`dblclick`: fires when an element is double-clicked on.
29
34
*`keyup`: fires when an key is pressed and released.
30
35
*`keydown`: fires immediately when a key is pressed.
31
36
*`mouseup`: fires when a mouse button is pressed and released.
32
37
*`mousedown`: fires when a mouse button is pressed.
33
38
***selector**: (optional) a valid jQuery/CSS selector. with some events (such as key presses), this checks for focus; with others it checks for the target element of the event (such as mouse clicks). if no selector is provided, the event is bound to the document element.
39
+
***once**: (optional) the keyword `once`. If included, overrides the normal behavior of `<<on>>` (and `<<event>>`) to create a single-use event handler.
34
40
***keycode**: an integer. allows you to determine which key or mouse button triggered the event and react accordingly. you can find keycodes [here](http://keycode.info/).
35
41
36
42
**Usage**:
37
43
```
38
44
/% stow/unstow the ui-bar on double-click %/
39
-
<<event 'dblclick' '#ui-bar'>>
45
+
<<on 'dblclick' '#ui-bar'>>
40
46
<<toggleclass '#ui-bar' 'stowed'>>
41
-
<</event>>
47
+
<</on>>
42
48
43
49
/% set up some hotkeys %/
44
-
<<event 'keyup'>>
50
+
<<on 'keyup'>>
45
51
<<which 67>> /% the c key %/
46
52
<<if not tags().includes('menu')>> /% avoid menu loop %/
47
53
<<goto 'character-menu'>>
@@ -52,17 +58,27 @@ This macro set can be used to add more interaction to your game; things like key
Allows you to simulate any event on any element. This macro is useful for triggering events you may not otherwise have easy access to.
63
79
64
80
***type**: a valid jQuery event type
65
-
***selector**: a valid jQuery/CSS selector. if omitted, defaults to the document element
81
+
***selector**: (optional) a valid jQuery/CSS selector. if omitted, defaults to the document element
66
82
67
83
**Usage**:
68
84
```
@@ -71,4 +87,27 @@ Allows you to simulate any event on any element. This macro is useful for trigg
71
87
<<which 27>>
72
88
<<trigger 'click' '#ui-dialog-close'>>
73
89
<</event>>
74
-
```
90
+
```
91
+
92
+
### Macro: `<<off>>`
93
+
94
+
**Syntax**:`<<off type [selector]>>`
95
+
96
+
Allows you to remove an event handler.
97
+
98
+
***type**: a valid jQuery event type; may include namespaces
99
+
***selector**: (optional) a valid jQuery/CSS selector. if omitted, defaults to the document element
100
+
101
+
**Usage**:
102
+
103
+
```
104
+
/% removes all events created through this macro set %/
105
+
<<off '.macro-event'>>
106
+
107
+
/% remove all `dblclick` handlers from the `#ui-bar` element %/
108
+
<<off 'dblclick' '#ui-bar'>>
109
+
```
110
+
111
+
### Setting: `setup.eventMacroNamespace`
112
+
113
+
Handlers set up via this macro set are given a namespace automatically. The default value of this name space is `"macro-event"`. You may change this value to change the namespace if you want. Omit the dot.
0 commit comments