letrazzrot wrote:
Code:
VerbRule(TieTo)
'tie' singleDobj 'to' singleIobj
: TieToAction
askIobjResponseProd = toSingleNoun
verbPhrase = 'tie/tying (what) (to what)'
;
This defines your basic rule to support ">tie X to Y". It will also allow the ">tie X to" syntax, and the askIobjResponseProd statement means that in this case, if the player omits the indirect object and the parser asks him to pick one, you want to treat the response as a noun, rather than a topic or a literal or whatever.
(toSingleNoun is the default value for
askIobjResponseProd so this line can be omitted.)
However, this verb rule does not cover ">tie" or ">tie X". The player will be told that the story doesn't understand that command, which isn't what we want at all. We just want him to be more specific. For that we need...
letrazzrot wrote:
Code:
VerbRule(TieToWhat)
[badness 500] 'tie' dobjList
: TieToAction
verbPhrase = 'tie/tying (what) (to what)'
construct()
{
/* set up the empty indirect object phrase */
iobjMatch = new EmptyNounPhraseProd();
iobjMatch.responseProd = toSingleNoun;
}
;
Here you've noticed the [badness 500] before the syntax. What this means is that we never want to use this rule in place of the "real" TieTo rule, even though ">tie X to Y" could theoretically be parsed as ">tie X [with some stuff the parser ignores]" and match this rule instead.
This is what covers the ">tie" input: if the player enters that, he'll be asked what he wants to tie. If the player types "X", or if he enters something like ">tie X", he's satisfied the parameters of this rule. All it wants is a verb and a direct object. So the rule is ready to create the action.
But wait! TieToAction requires both a direct and an indirect object. If we jump straight to it, TieToAction will try to access properties of an indirect object that doesn't exist, and we'll get a nil reference error.
That's where the construct() function comes in. It's saying, when you first set up this VerbRule, give it a placeholder for the indirect object. That placeholder is EmptyNounPhraseProd, because this particular rule can't ever match input that includes an indirect object - otherwise it would have matched our first rule. EmptyNounPhraseProd is a cue to the parser to go back to the player and ask him to pick something.
The next line tells it to treat whatever the player types as a single noun. This covers the same ground as askIobjResponseProd = toSingleNoun did in our first rule, except it was optional there and it's required here. By default,
EmptyNounPhraseProd.responseProd is nil, so if we don't supply a value we'll get another nil reference error.