Skip to content
selfsame edited this page Jan 18, 2015 · 15 revisions

Verbs represent player commands.

Verbs are bound as shown::

#takes name, regex, and optional map of special verb forms
bind.verb("sleep", "sleep|doze|z", {"past":"slept", "progressive":"sleeping"})

#takes name, and 1-n pattern args (can be called multiple times)
bind.verb_pattern("sleep", "on|in|under{1}","{1}")

input string resolution

core.verbs.determine(string) will attempt to match the player input to a verb, then a verb_pattern.
A list of 'tokens' will be returned. The standard.player.input module makes use of this to contruct a scope list of entities and resolve tokens.

standard.player.input will call a function of the same name as the verb, with arguments of the player and the resolved objects. This is a rather important concept of the standard game libraries, and it's worth taking a look at game/standard/player/input.py and game/standard/scope.py

example of a rule for the 'sleep' verb

@given("player", "supporter")
def sleep(a, b):
  report("[Subject] go[es] to sleep on [object].")

token structures

the verb_pattern bracket tags dictate how an input string is divided into objects, and have a form {1} {2}etc. This allows special object ordering, as in shoot "{1}with{2}" or "{2}at{1}".

token forms

a tag returns a token {"noun":{"string":string}} a tag with the form {1:text} will return a token {"text":string}

containment is currently hard coded in core.verbs, and likely to change. Input "foo in the bar inside qux" will construct a tag like:

{"string":"qux",
 "holder":{"string":"bar",
           "holder":{"noun":{"string":"foo"}}}}

If containment is not wanted, you can capture containment between pattern tags:

bind.verb_pattern("drop", "{1}inside (of)?|in(to)?{2}")

NOTE: all articles are stripped during tokenization

Clone this wiki locally