Inform 7: Altering room descriptions on the fly. (SOLVED)

As a way to represent a descent into madness, I want to automatically edit room descriptions. Here is the what I have come up with so far. Mostly stolen from examples, of course.

[code]The fancy examining rule is listed instead of the standard examining rule in the carry out examining rules.

Printing the description of something is an activity.

printing the description of a location is an activity.

This is the fancy examining rule:
carry out the printing the description activity with the noun;
rule succeeds.

Rule for printing the description of something (called item):
let N be indexed text;
let N be “[description of item]”;
if craziness is true:
[ craziness stuff here ]
say “[N]”;

Rule for printing the description of a location:
let N be indexed text;
let N be “[description of the location of the player]”;
if craziness is true:
[ craziness stuff here ]
say “[N]”;[/code]

This works for the descriptions of items, but it doesn’t work for room descriptions.

Offhand and perhaps wrong diagnoses:

A room is an object rather than a thing, so “printing the description of something” might not catch it. And “a location” is probably getting treated the same as “the location,” which is the room the player is in. That rule is more likely to work if you write “for printing the description of a room.”

But more importantly, the action that prints the room description is not examining the room, but looking. So you need a fancy looking rule as well. Note that this will just catch the room description, not anything produced by “You can also see” or rules for writing paragraphs about things or anything like that. (I think.)

Also, why are you using indexed text? If all you want to do is print out the normal description there are simpler ways to do that with new rules for looking and examining that trigger after the standard ones. If you’re taking the normal descriptions and doing stuff inside them (like changing all the "r"s to "w"s to Elmer Fuddify them), then indexed text would be the way to go.

You can say:

The description of the Kitchen is “[Kitchen-description]”.
To say Kitchen-description:
[…any code you want, including a call to your activity.]

This deals with the “description” property, and has nothing to do with your “printing the descrption” activity. You could invoke the activity, or put your logic directly in the phrase.

This does not fix it.

I tried The fancy looking rule is listed instead of the standard looking rule in the carry out looking rules. but this threw an exception. I have never really understood the difference between looking and examining.

Specifically: In ‘The fancy looking rule is listed instead of the standard looking rule in the carry out looking rules’ , you gave ‘the standard looking rule’ where a rule was required.

This would work, but my game is already quite large, so this would involve a bunch of backtracking. I would rather find the tech that does it automatically.

That’s because there’s no rule named “The standard looking rule.” If you want to get an idea of what rules are doing what, type “rules” in your game and then try an action. You’ll discover that the rule that prints the room description (the stuff that you put in quotes after the name of your room) is called “room description body text rule.” You’ll also discover that there are a lot of other rules in there.

The difference between looking and examining is that looking is the action you perform when you type “look,” which gives you some text about the room you’re in (and other stuff), and examining is the stuff that you perform when you type “x widget,” which gives you some text about the widget. When you move to a new room it (as a rule) automatically performs a looking action for you. Not sure what else you want for a difference? They’re different actions, governed by different rules.

As for the size of your game, if you don’t do it right now you’ll probably wind up doing even more backtracking later. You haven’t mentioned yet exactly what you’re trying to do with the madness stuff; are you printing things after the ordinary room description, or are you doing something else? As I said, if you just want to print more stuff after the room description there are easier ways to do that.

This might be a solution (without the need of new activitites or rule substitutions):

[code]To say the description of (item - object):
let N be indexed text;
let N be “[description of item]”;
if craziness is true:
let M be a random number between 1 and the number of words in N;
replace word number M in N with “jabberwocky”;
say “[N]”;

To print the location’s description:
let N be indexed text;
let N be “[description of the location of the player]”;
if craziness is true:
let L be a random number between 1 and the number of words in N;
replace word number L in N with “jabberwocky”;
say “[N]”.
[/code]
However, the phrase ‘To print the location’s description’ is defined by the Standard Rules (that use it in the room description body text rule in the carry out looking rulebook), and I’m not at all sure about how safe it is to redefine it in this particular fashion. (Actually, the Standard Rules recommend not tampering with it.) Still, it seems to work for the simplest cases at least.

I am translating it into indexed text so I can scramble random characters. This works on the examination bit, it just wasn’t relevant, so I didn’t post it.

I will try to learn more of the rules that govern standard play, starting with the room description body text rule.

As an alternate possible solution, the way I did this for my ultrashort/“experimental” game Sugar used Ron Newcomb’s Output Filtering extension, which itself uses Eric Eve’s Text Capture extension. Output Filtering allows you a hook into the game text right before it hits the screen, so I was able to mess with all of the game’s output including library messages. If you’d like me to send you my source, PM me with your email address.

This works, but puts a pretty significant performance hit in (like 3-5 seconds per room). Still, good enough. Thanks!

Yeah, I can imagine. The performance will probably be a little better when you run the game in an interpreter rather than in the IDE, though. Which is good, for I have some doubts that a 3 seconds pause every time you look around in a room really will be acceptable to most players (well, yes, perhaps, if the thing doesn’t start until the player is already well immersed in the game).

Try this.

[spoiler][code]“Test”

The standard examining rule is not listed in the carry out examining rulebook.
The examine directions rule is not listed in the carry out examining rulebook.
The examine containers rule is not listed in the carry out examining rulebook.
The examine supporters rule is not listed in the carry out examining rulebook.
The examine devices rule is not listed in the carry out examining rulebook.
The examine undescribed things rule is not listed in the carry out examining rulebook.

Printing the description of something is an activity.

Last for printing the description of a something (called the chosen item) (this is the default item description printing rule):
if the description of the chosen item is not “” begin;
say the description of the chosen item;
say line break;
otherwise;
say “Error - [The chosen item] lacks a description.”;
end if.

Last for printing the description of a room (called the chosen room) (this is the default room description printing rule):
if the description of the chosen room is not “” begin;
say the description of the chosen room;
say line break;
otherwise;
say “Error - [The chosen room] lacks a description.”;
end if.

Last for printing the description of a dark room (this is the default dark room description printing rule): say “It is pitch dark, and you can’t see a thing.”.

Carry out examining (this is the fancy examining rule): carry out the printing the description activity with the noun.

Carry out looking (this is the improved room description body text rule):
if in darkness begin;
carry out the printing the description of a dark room activity;
otherwise;
carry out the printing the description activity with the visibility ceiling;
end if.

The improved room description body text rule is listed instead of the room description body text rule in the carry out looking rulebook.

Rule for printing the description of the testing room: say “This is the new description.”.

Rule for printing the description of the treasure: say “This is the new description for the treasure.”.

The Testing Room is A Room. The description of the testing room is “This is the standard description.”.

Some treasure is in the testing room. The description of the treasure is “This is the standard description for the treasure.”.

Test me with “x treasure / look”.[/code][/spoiler]

Your method is correct, but you need to replace the relevant looking rule to use the activity that you have defined. You can now add text before and after a description with the respective before and after rules, like this.

[code]Before printing the description of something: say “Text before the item description”.

Before printing the description of a room: say “Text before the room description”.

After printing the description of something: say “Text after the item description”.

After printing the description of a room: say “Text after the room description”.[/code]

You can also add new rules to print a description when a condition is satisfied, like this.

[code]A room can be either tiny, small, medium, large of huge.

Rule for printing the description of a tiny room: say “This room is tiny!”.

Rule for printing the description of a huge room: say “This room is huge!”.[/code]

Or even like this.

Rule for printing the description of a room (called the chosen room) when the chosen room encloses a rat: say "You can smell a rat!".

You can do similar things with things too.

Hope this helps.