Inform7: How to store the current text of a response in a text variable?

Hi,

I’m in the process of learning Inform7, and I’m new to this forum.

So much about myself. On to my current problem. :slight_smile:

I want to store the text of a response in a text variable, so I can change the response and still reproduce the old text later.

I tried the following.

oldResponseText is some text that varies.
newResponseText is some text that varies.

When play begins:
    now oldResponseText is "[text of the can't go that way rule response (A)]";
    now the can't go that way rule response (A) is "This is not an exit.";
    now newResponseText is "[text of the can't go that way rule response (A)]";
    say oldResponseText; [prints This is not an exit. I would like it to print You can't go that way.]
    say newResponseText; [prints This is not an exit. That's ok.]

I understand that this doesn’ work because “[text of the can’t go that way rule response (A)]” is evaluated when it’s printed, so saying oldResponseText after the can’t go that way rule response (A) is changed produces the new text.

I also tried some variations of this, but they either didn’t compile or didn’t work.

Does anybody know how to store the original text of the can’t go that way rule response (A) in oldResponseText?

And no, I don’t mean looking it up in the standard rules and writing

Now oldResponseText is "[We] [can't go] that way.".

:slight_smile:

Here’s an example how I would use the old response text.

Consider the following setup.

West Wing is a room.

East Wing is east of West Wing.

Now, if the player is in West Wing and tries to go in a direction he can’t, I want to print “This is not an exit.”.

If the player is anywhere else and tries to go in a direction he can’t, I want to print the standard response.

I could write:

The can't go that way rule response (A) is
"[if the location is West Wing]
This is not an exit.
[otherwise]
You can't go that way.
[end if]".

But I don’t like this because I have duplicated the text of the standard response. Here I could use the oldResponseText in the [otherwise] clause.

I could also write

Check the player going:
    if the room gone from is West Wing:
        if the room gone to is nothing:
            say "This is not an exit.";
            stop the action.

But I don’t like this either because here I have duplicated logic from the standard rules.

So it would be handy to have the text of the standard response in a text variable.

Thanks for you help.

John

Welcome to the forum!

If you want to freeze a text substitution at the moment you evaluate it, the way to do it is with “the substituted form of”:

Lab is a room.

oldResponseText is some text that varies.
newResponseText is some text that varies.

When play begins:
    now oldResponseText is the substituted form of "[text of the can't go that way rule response (A)]";
    now the can't go that way rule response (A) is "This is not an exit.";
    now newResponseText is "[text of the can't go that way rule response (A)]";
    say oldResponseText; [prints You can't go that way. Yay!] 
    say newResponseText; [prints This is not an exit. That's ok.]

See 20.7 of Writing with Inform (the built-in documentation)–by default a variable containing a text substitution will be evaluated as the text substitution every time, but if you use “substituted form” then it gets evaluated into the string and kept that way.

1 Like

Very cool. :+1:

That solves my problem completely.

Thank you!