@@ -3,94 +3,56 @@ description: |
33 Register an Action
44---
55
6- TODO
6+ Actions are resources in Parley used to execute defined functionality during the
7+ running of a Dialogue Sequence. For example, an Action could contain
8+ functionality to: emit a signal, register a journal entry, or update state.
79
8- Actions are resources in Parley used to: TODO.
10+ Actions are stored in an action store which can be configured in the Parley
11+ settings.
912
10- <!-- For example, one might want to display different dialogue
11- depending on whether Alice gave a coffee or not.
12-
13- Facts are stored in a fact store which can be configured in the Parley settings.
14-
15- In this guide, we will create a fact that can be used to create a Condition Node
16- in the corresponding
17- [create a Condition Node guide](./create-condition-node.md).
13+ In this guide, we will create a action that can be used to create an Action Node
14+ in the corresponding [ create an Action Node guide] ( ./create-action-node.md ) .
1815
1916## Pre-requisites
2017
2118- Ensure you have familiarised yourself with the
22- [Condition Node](../nodes/condition -node.md) docs.
19+ [ Action Node] ( ../nodes/action -node.md ) docs.
2320- Parley is [ installed] ( ./installation.md ) and running in your Godot Editor.
2421- You have created a basic Dialogue Sequence before. Consult the
25- [getting started guide](./create-dialogue-sequence.md) for more info. -->
26-
27- <!-- TODO: update when Parley supports creation of Fact -->
28-
29- <!-- ## Instructions
30-
31- > **Note:** it is assumed that the default Parley settings are used for the fact
32- > store and it is stored at: `res://facts/fact_store_main.tres`
22+ [ getting started guide] ( ./create-dialogue-sequence.md ) for more info.
3323
34- - Create a Fact script (ensure that it extends the `FactInterface` class) at:
35- `res://facts/alice_gave_coffee_fact.gd`
24+ ## Instructions
3625
37- ```gdscript
38- extends FactInterface
26+ ![ Register an Action] ( ../../../www/static/docs/register-action/register-action.gif )
3927
40- func execute(_ctx: Dictionary, _values: Array) -> bool:
41- print('Alice did indeed give coffee')
42- # Note, you can return any value here, it doesn't
43- # necessarily have to be a bool
44- return true
45- ```
28+ > [ info] : it is assumed that the default Parley settings are used for the fact
29+ > store and it is stored at: ` res://facts/fact_store_main.tres ` . You can find
30+ > more information on changing the default Parley settings
31+ > [ here] ( ../reference/parley-settings.md ) .
4632
47- - [OPTIONAL] If the return type of your fact, is **not** of type `bool`, it is
48- recommended to return well-known values of the fact (for example, when using a
49- [Match Node](../nodes/match-node.md)). For example:
33+ - Create an Action script (ensure that it extends the ` ParleyActionInterface `
34+ class) at: ` res://actions/advance_time_action.gd `
5035
5136``` gdscript
52- extends FactInterface
53-
54- enum Ball {
55- RED = 1,
56- YELLOW = 2,
57- PINK = 6,
58- BLUE = 5,
59- }
37+ extends ParleyActionInterface
6038
61- func execute(ctx: Dictionary, _values: Array) -> int:
62- return ctx.get('ball', 0)
63-
64- func available_values() -> Array[Ball]:
65- return [
66- Ball.RED,
67- Ball.YELLOW,
68- Ball.PINK,
69- Ball.BLUE,
70- ]
39+ func execute(_ctx: Dictionary, values: Array) -> int:
40+ print("Advancing time by %s" % [values[0]])
41+ return OK
7142```
7243
73- - Open up the inspector for `res://facts/fact_store_main.tres` in the Godot
74- Editor and click `Add Element`:
75-
76- 
77-
78- - Then, click the empty element and choose `New Fact`:
79-
80- 
81-
82- - Now populate the fact ID by using the same element ID (recommended but not
83- essential) and choose a sensible name for the Fact in the store:
84-
85- 
86-
87- - Then, drag the fact script created earlier to the `<empty>` ref field:
88-
89- 
90-
91- <!-- TODO: change/remove this when supported Parley -->
92-
93- <!-- - Finally, reload the Godot project and the new fact should be available to use
94- in Parley!
95-
96-  -->
44+ 1 . Open up the ` ParleyStores ` dock in the Godot Editor and click ` Add Action ` .
45+ 2 . Give your new action an ID. In our example, we use: ` main:advance_time ` .
46+ 3 . Give your new action a name. In our example, we use: ` Advance Time ` .
47+ 4 . Link your created action script with the Action using the resource inspector
48+ (labelled ` Ref ` ).
49+
50+ > [ tip] : You can use the resource editors in ` ParleyStores ` to quickly navigate
51+ > to the relevant resource for editing. You can also add resources using the
52+ > resource editor dropdown field instead of dragging.
53+
54+ 5 . You should now see that the Action is available in the Action node dropdown
55+ options. Select ` Advance Time ` in the options to associate it with the
56+ selected Action Node.
57+ 6 . Test out your new Action within the Dialogue Sequence by clicking the Test
58+ Dialogue Sequence from start button.
0 commit comments