Nil object reference (adv3Lite)

EDIT: Solved by Eric Eve. One edited line of code near the start of askAmbiguous:

if (role is in (DirectObject, ActorRole))


This is a tough one. In response to an absurd command – an attempt to say hello to an inanimate object when there are multiple objects in scope that the noun could refer to – the library will sometimes throw a run-time nil object reference. But not always. Just the fact that the two objects derive from the same author-defined class is not sufficient. The command ‘coins, hi’ does not trigger the run-time error. However, ‘desk, hi’ or ‘photo, hi’ does cause the error. At a guess, this is because the coins are indistinguishable, while the desks and photos have distinguishing names.

The error is on line 3797 of english.t. This is in the nounRoleQuestion function, which is called by the askAmbiguous function. So I open Watch Expressions and take a look at the value of cmd.verbProd. It all seems sensible enough; one of the desks, at least, is identified as a possible object to which to direct the command. And yet – aha! There’s no cmd.verbProd.missingQ!

That is, the command Hello has no missingQ. So I add one by editing the library code. And now the error occurs on the following line, line 3800. The command Hello (defined in actions.t) is an IAction. Thus the line

q = q[role == DirectObject ? 1 : role == IndirectObject ? 2 : 3];

has, apparently, no meaning. Now the error I’m seeing is “index out of range.” q was, for a moment there, the missingQ that I added to the library: ‘who do you want to greet’. According to Watch Expressions, role is ActorRole. One would expect that, because role is neither DirectObject nor IndirectObject, q would be assigned the value q[3]. But because there’s no split at ; (there being no ; at all in the missingQ), q has been reassigned to the value nil. Thus it has no list or array [], so the index is out of range.

2 Likes