Module: Gamefic::Scriptable::Actions
- Includes:
- Queries
- Included in:
- Narrative, Gamefic::Scriptable
- Defined in:
- lib/gamefic/scriptable/actions.rb
Overview
Scriptable methods related to creating actions.
Instance Method Summary collapse
-
#after_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated after a character executes an action.
-
#before_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated before a character executes an action.
-
#interpret(command, translation) ⇒ Syntax
Create an alternate Syntax for a response.
-
#meta(verb, *args) {|| ... } ⇒ Symbol
Create a meta response for a command.
-
#respond(verb, *args) {|| ... } ⇒ Symbol
Create a response to a command.
-
#synonyms ⇒ Array<Symbol>
Synonyms are a combination of the rulebook’s concrete verbs plus the alternative variants defined in syntaxes.
- #syntaxes ⇒ Array<Syntax>
-
#verbs ⇒ Array<Symbol>
Verbs are the symbols that have responses defined in the rulebook.
Methods included from Queries
#abstract, #anywhere, #available, #children, #descendants, #myself, #parent, #plaintext, #siblings
Methods included from Proxies
Instance Method Details
#after_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated after a character executes an action. When a verbs are specified, the proc will only be evaluated if the action’s verb matches them.
75 76 77 |
# File 'lib/gamefic/scriptable/actions.rb', line 75 def after_action *verbs, &block rulebook.hooks.after_action self, *verbs, &block end |
#before_action(*verbs) {|| ... } ⇒ Action::Hook
Add a proc to be evaluated before a character executes an action. When verbs are specified, the proc will only be evaluated if the action’s verb matches them.
64 65 66 |
# File 'lib/gamefic/scriptable/actions.rb', line 64 def before_action *verbs, &block rulebook.hooks.before_action self, *verbs, &block end |
#interpret(command, translation) ⇒ Syntax
Create an alternate Syntax for a response. The command and its translation can be parameterized.
93 94 95 |
# File 'lib/gamefic/scriptable/actions.rb', line 93 def interpret command, translation rulebook.calls.add_syntax Syntax.new(command, translation) end |
#meta(verb, *args) {|| ... } ⇒ Symbol
Create a meta response for a command. Meta responses are very similar to standard responses, except they’re flagged as meta (‘Response#meta?`) to indicate that they provide a feature that is not considered an in-game action, such as displaying help documentation or a scoreboard.
52 53 54 55 |
# File 'lib/gamefic/scriptable/actions.rb', line 52 def (verb, *args, &proc) rulebook.calls.add_response Response.new(verb, self, *args, meta: true, &proc) verb end |
#respond(verb, *args) {|| ... } ⇒ Symbol
Create a response to a command. A Response uses the ‘verb` argument to identify the imperative verb that triggers the action. It can also accept queries to tokenize the remainder of the input and filter for particular entities or properties. The `block“ argument is the proc to execute when the input matches all of the Response’s criteria (i.e., verb and queries).
32 33 34 35 |
# File 'lib/gamefic/scriptable/actions.rb', line 32 def respond(verb, *args, &proc) rulebook.calls.add_response Response.new(verb, self, *args, &proc) verb end |
#synonyms ⇒ Array<Symbol>
Synonyms are a combination of the rulebook’s concrete verbs plus the alternative variants defined in syntaxes.
127 128 129 |
# File 'lib/gamefic/scriptable/actions.rb', line 127 def synonyms rulebook.synonyms end |
#syntaxes ⇒ Array<Syntax>
132 133 134 |
# File 'lib/gamefic/scriptable/actions.rb', line 132 def syntaxes rulebook.syntaxes end |
#verbs ⇒ Array<Symbol>
Verbs are the symbols that have responses defined in the rulebook.
109 110 111 |
# File 'lib/gamefic/scriptable/actions.rb', line 109 def verbs rulebook.verbs end |