This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tutorial:mattscript-documentation [2025/02/24 23:05] – admin | tutorial:mattscript-documentation [2025/02/27 00:44] (current) – admin | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| For example, an '' | For example, an '' | ||
| - | < | + | < |
| $Event(11005000, | $Event(11005000, | ||
| if (ThisEventSlot()) { | if (ThisEventSlot()) { | ||
| Line 24: | Line 24: | ||
| When saving a file, it is converted into this equivalent '' | When saving a file, it is converted into this equivalent '' | ||
| - | < | + | < |
| Event(11005000, | Event(11005000, | ||
| SkipIfEventFlag(2, | SkipIfEventFlag(2, | ||
| Line 51: | Line 51: | ||
| As a simple example, suppose there is an area in the map, and as long as a fight is active, we want to slowly auto-heal the player as long as they are under 70% HP and in that area. A simple version of that might be as follows: | As a simple example, suppose there is an area in the map, and as long as a fight is active, we want to slowly auto-heal the player as long as they are under 70% HP and in that area. A simple version of that might be as follows: | ||
| - | < | + | < |
| $Event(13705010, | $Event(13705010, | ||
| WaitFor(InArea(10000, | WaitFor(InArea(10000, | ||
| Line 69: | Line 69: | ||
| Finally, condition functions can be combined using the logical operators ''&&'' | Finally, condition functions can be combined using the logical operators ''&&'' | ||
| - | < | + | < |
| $Event(13705010, | $Event(13705010, | ||
| WaitFor(InArea(10000, | WaitFor(InArea(10000, | ||
| Line 81: | Line 81: | ||
| One useful trick for dealing with boolean logic is De Morgan' | One useful trick for dealing with boolean logic is De Morgan' | ||
| - | < | + | < |
| $Event(9182, | $Event(9182, | ||
| EndIf(!CharacterType(10000, | EndIf(!CharacterType(10000, | ||
| Line 94: | Line 94: | ||
| Which is equivalent to the following: | Which is equivalent to the following: | ||
| - | < | + | < |
| $Event(9182, | $Event(9182, | ||
| EndIf(!CharacterType(10000, | EndIf(!CharacterType(10000, | ||
| Line 109: | Line 109: | ||
| An even more fromsoft-ian way of structuring the 70% HP example might be as follows, which brings us to condition variables: | An even more fromsoft-ian way of structuring the 70% HP example might be as follows, which brings us to condition variables: | ||
| - | < | + | < |
| $Event(13705010, | $Event(13705010, | ||
| fightOver = EventFlag(13700860); | fightOver = EventFlag(13700860); | ||
| Line 124: | Line 124: | ||
| For the most part, '' | For the most part, '' | ||
| - | < | + | < |
| $Event(13705011, | $Event(13705011, | ||
| WaitFor(InArea(10000, | WaitFor(InArea(10000, | ||
| Line 132: | Line 132: | ||
| This is compiled down to this low-level representation: | This is compiled down to this low-level representation: | ||
| - | < | + | < |
| Event(13705011, | Event(13705011, | ||
| IfInoutsideArea(AND_01, | IfInoutsideArea(AND_01, | ||
| Line 142: | Line 142: | ||
| Another way of writing the event using an explicit condition variable would be like this. (Note: it is strongly recommended to use the ''&&'' | Another way of writing the event using an explicit condition variable would be like this. (Note: it is strongly recommended to use the ''&&'' | ||
| - | < | + | < |
| $Event(13705011, | $Event(13705011, | ||
| areaLowHp &= InArea(10000, | areaLowHp &= InArea(10000, | ||
| Line 165: | Line 165: | ||
| A common usage of condition variables is to have conditions whose definitions can change based on event parameters, like this excerpt from the DS3 fog gate traversal event: | A common usage of condition variables is to have conditions whose definitions can change based on event parameters, like this excerpt from the DS3 fog gate traversal event: | ||
| - | < | + | < |
| $Event(20005800, | $Event(20005800, | ||
| ... | ... | ||
| Line 180: | Line 180: | ||
| Plenty of other interesting uses are possible, like this Sekiro event. Condition variables can basically be used anywhere a condition is expected, not just in '' | Plenty of other interesting uses are possible, like this Sekiro event. Condition variables can basically be used anywhere a condition is expected, not just in '' | ||
| - | < | + | < |
| $Event(11105130, | $Event(11105130, | ||
| SetEventFlag(11100130, | SetEventFlag(11100130, | ||
| Line 202: | Line 202: | ||
| In this case, you could also implement it as follows, although this uses slightly more condition groups behind the scenes. | In this case, you could also implement it as follows, although this uses slightly more condition groups behind the scenes. | ||
| - | < | + | < |
| $Event(11105130, | $Event(11105130, | ||
| if ((!EventFlag(8302) && EventFlag(11100301)) || (EventFlag(8302) && EventFlag(11100480))) { | if ((!EventFlag(8302) && EventFlag(11100301)) || (EventFlag(8302) && EventFlag(11100480))) { | ||
| Line 253: | Line 253: | ||
| A toy example of their use: | A toy example of their use: | ||
| - | < | + | < |
| $Event(9194, | $Event(9194, | ||
| GotoIf(L0, EventFlag(6006)); | GotoIf(L0, EventFlag(6006)); | ||
| Line 267: | Line 267: | ||
| Becomes: | Becomes: | ||
| - | < | + | < |
| Event(9194, Default, function() { | Event(9194, Default, function() { | ||
| GotoIfEventFlag(Label.LABEL0, | GotoIfEventFlag(Label.LABEL0, | ||
| Line 300: | Line 300: | ||
| Const variable declarations in events are permitted. An example of constants and simple expressions: | Const variable declarations in events are permitted. An example of constants and simple expressions: | ||
| - | < | + | < |
| $Event(13105265, | $Event(13105265, | ||
| const bossEntity = 3100395; | const bossEntity = 3100395; | ||
| Line 316: | Line 316: | ||
| For loops are specially processed by MattScript. The loop definition itself is retained as pure JS, but the contents are compiled. Regular for-loops (with '' | For loops are specially processed by MattScript. The loop definition itself is retained as pure JS, but the contents are compiled. Regular for-loops (with '' | ||
| - | < | + | < |
| $Event(13105266, | $Event(13105266, | ||
| const bossEntities = [3100395, 3100398, 3100399]; | const bossEntities = [3100395, 3100398, 3100399]; | ||
| Line 331: | Line 331: | ||
| In cases where you're repeating a series of if statements which require condition variables, this is fairly difficult even without MattScript. You can use a no-op condition group reset in between iterations. | In cases where you're repeating a series of if statements which require condition variables, this is fairly difficult even without MattScript. You can use a no-op condition group reset in between iterations. | ||
| - | < | + | < |
| $Event(13105267, | $Event(13105267, | ||
| WaitFor(EventFlag(13105265)); | WaitFor(EventFlag(13105265)); | ||
| Line 350: | Line 350: | ||
| Typed event initializations allow for event declarations and initializations where the event parameters have names and types. They are not part of MattScript but they do preprocess the source file using the same parser routine. | Typed event initializations allow for event declarations and initializations where the event parameters have names and types. They are not part of MattScript but they do preprocess the source file using the same parser routine. | ||
| - | < | + | < |
| // Old-style events use parameter names starting with X | // Old-style events use parameter names starting with X | ||
| $Event(73791090, | $Event(73791090, | ||