Bug in I7 from Documentation Example 345 - Wesponses?

Implementing a variation on the standard ‘Rule for issuing the response text of a response’ I copied code from the Documentation but immediately ran into an illegal object reference error when the response contains an object reference rather than being plain text:

"Wesponses"

The Office is a room. Barry Kripke is a man in the Office. Barry carries a gun.

The response inhibition is initially false.

Rule for issuing the response text of a response (called R) when response inhibition is false:
	now response inhibition is true;
	let output be "[text of R]";
	now response inhibition is false;
	replace the text "r" in output with "w";
	replace the text "R" in output with "W";
	say "[output]".

Test me with "i / x barry / listen / waffle / jump / take gun"

Results in:

Wesponses
An Interactive Fiction
Release 1 / Serial number 190706 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

Office
You can see Barry Kripke hewe.

>test me
(Testing.)

>[1] i
You awe cawwying nothing.

>[2] x barry
You see nothing special about Bawwy Kwipke.

>[3] listen
You heaw nothing unexpected.

>[4] waffle
That's not a vewb I wecognise.

>[5] jump
You jump on the spot.

>[6] take gun
That seems to belong to <illegal object numbew 505510>.

>

This looks like a plain bug to me, but equally I can’t see why this should happen just because the request to build a response is evoked from this code.

Has anyone else come across this? I can’t see that it’s a reported bug…

Well it’s definitely a bug, and it happens slightly differently in Z-code and Glulx, so it’s an Inform bug rather than an interpreter bug.

It seems likely to me that the particular issue is that the response contains a reference to a local variable from a different code block. The problematic part is a reference to “[the owner]”, and the owner is a local variable from the can’t take people’s possessions rule.

Probably no one has run across this because (as the documentation says) this isn’t very useful. If you wanted to substitute ‘w’ for ‘r’ everywhere, you could use Text Capture to capture everything you were printing and do the substitution in the captured text. Doing something to responses and only responses isn’t that great anyway.

For a laugh, type “responses all” while running this.

1 Like

This works:

GlobalOutput is a text that varies.

Rule for issuing the response text of a response (called R) when response inhibition is false:
	now response inhibition is true;
	now GlobalOutput is "[text of R]";
	now response inhibition is false;
	replace the text "r" in GlobalOutput with "w";
	replace the text "R" in GlobalOutput with "W";
	say GlobalOutput;

I’m not sure why changing the variable to a global makes a difference. (The substitutions in the text can’t refer to local variables, but for the text itself it shouldn’t make a difference.) Nonetheless, there you are.

Thanks. Confirm this works for me too. Weird. Furthermore, using ‘the substituted form of “[text of R]”’ with a local text variable doesn’t work either.

This reminds me of the thing where we had to use a global text variable to pass text from a local variable to an action applying to one topic. There’s no particular reason I can see why it should have to work this way for responses, but response texts must not quite be vanilla text substitutions.

From Zarf’s unexpected workaround, it would seem indeed to be another inexplicable scoping bug.

As to usefulness, it was because I was still playing around with the ‘Tidying’ code and seeking a more generic rather than hard-coded way of printing (without blank lines) responses in the form

highball glass: You’re carrying too many things already.
giant glass: That’s fixed in place.
tall glass: That seems to belong to Bob.

as before, using the fact of a response having being printed as a surrogate marker to the code calling ‘try silently …ing’ for the action having failed.
which led to (in its post-Zarf incarnation):

response output is a text that varies.
	
Rule for issuing the response text of a response (called R) when response inhibition is false and announce multiple objects flag is true: 
	now response inhibition is true; 
	now response output is "[text of R]"; 
	now response inhibition is false; 
	say "[noun]: [response output][run paragraph on]";
	now standard response rule flag is true;

I did :slight_smile: