Input without verb

Seems I got a bit rusty. Does anybody remember how to make Dialog understand a sentence with only a single object

like: >silver key

to examine the silver key object? The grammar does not allow to begin an input with a noun, but I remember it worked some time ago.

There are two ways to do this.

First is (understand $Words as $Action). This is a more versatile way to do parsing, and it used to be the only way before the (grammar $ for $) system was introduced—in fact, one of the built-in rules for (understand $ as $) consults the (grammar $ for $) table, so everything comes back to understand in the end.

Second, though, this particular use case is built into Dialog! If you include the rule (default actions enabled) somewhere in your game, Dialog will understand a noun on its own as executing the “default action” on that object—normally, examining.

Here’s how that’s implemented under the hood:

(understand $Words as $Action)
	(default actions enabled)
	~{ (implicit action is $) ~(implicit action wants direction) }
	*(understand $Words as non-all object $Obj)
	~(empty $Obj)
	~($Obj = [1])
	(if) ($Obj = [a $RealObj]) (then)
		(default action $RealObj $Action)
	(else)
		(default action $Obj $Action)
	(endif)

(default action $Obj [examine $Obj])

In other words, if the player’s input matches one or more objects (but not ALL), and there’s no implicit action pending (“What do you want to attack the sphinx with?”), then it looks up the default action for that object, and returns that as the result of parsing.

3 Likes

Thank you very much, Daniel. This was it. I just failed to find the rule …