# A list where I modify a direction's name

So I have a chunk of code that works, and one that didn’t, and I suspect the working code can be cut down with a trick I don’t know about.

In this sample, you can switch random directions to “part-helped” if you wait. Then you may notice THINK will show you the list of directions. But it seems to recreate code found in the I6 core when listing stuff.

So it’s sufficient, but it doesn’t feel REALLY good.

SCORE looks like it should work, but sadly, the “for printing the name of” function recurses until memory fails.

"sandbox" by andrew schultz

volume basics

r1 is a room.

a direction can be part-helped. a direction is usually not part-helped.

show-towns is a truth state that varies.

to say q of (d - a direction):
let t be indexed text;
now t is "[d]" in title case;
say "[t] Directionville";

volume score (causes recursion error)

check requesting the score:
say "Score stuff.";
if number of part-helped directions > 0:
now show-towns is true;
say "You're sort of friends with [list of part-helped directions].";
now show-towns is false;
the rule succeeds;

for printing the name of a direction (called d) when show-towns is true:
say "[q of d]";

volume think (works, but I bet it can be a lot better)

the block thinking rule is not listed in any rulebook.

check thinking:
if number of part-helped direction is 0, say "You're pals with no town. Rats." instead;
say "You're pals with [part-help].";
the rule succeeds;

to say part-help:
let SD be number of part-helped directions;
say "the town[if SD > 1]s[end if] of ";
let count be 1;
repeat with D running through part-helped directions:
if count is 1:
say "[q of D]";
else if count is SD:
say " and [q of D]";
else:
say ", [q of D]";
increment count;

volume toggling directions randomly

check waiting:
let D be a random direction;
if D is part-helped:
now D is not part-helped;
else:
now D is part-helped;
say "Flipping [D].";

Is there a way to jig the check-the-score code so I can get “You are friends with North Directionville, South Directionville and East Directionville” or do I have to use the long way with the check-thinking code?

Thanks!

One way would be to use the printed name of d in title case, like this:

to say q of (d - a direction):
let t be the printed name of d in title case;
say "[t] Directionville";
2 Likes

This is 99% above my pay-grade, but it seems like the recursion error might be coming from the fact that the “to say q of d” code prints the name of a directions (“now t is ‘[d]’ in title case”), but when show-towns is true, that “[d]” is redirected to “[q of d]”. So the first code calls the second code, which calls the first code…

I haven’t tested, but maybe you can work around by juggling when show-towns is true?

2 Likes

This’ll fix score:

to say q of (d - a direction):
let t be indexed text;
let x be show-towns;
now show-towns is false;
now t is "[d]" in title case;
now show-towns is x;
say "[t] Directionville";

The recursion is because “[d] in title case” needs to print the direction name, which invokes q of d when show-towns is true, ad infinitum.

[Edited: or, basically, what Mike said.]

Yes, I agree with Mike regarding the cause of the error.

By the way, depending on the context in your game, you could shorten the code in several ways:

• I just saw that we don’t even need to assign the changed value to a temporary value as in my code above, we can just use say "[the printed name of d in title case] Directionville"; directly.

• And if you don’t need to use q of d elsewhere, you could do the say "[the printed name of d in title case] Directionville"; directly in the printing the name rule.

• And we can get rid of the booleans.

check requesting the score:
say "Score stuff.";
if number of part-helped directions > 0:
say "You're sort of friends with [list of part-helped directions].";
the rule succeeds;

for printing the name of a part-helped direction (called d) while requesting the score:
say "[the printed name of d in title case] Directionville";
1 Like

Inform 7 has a built-in facility for saying comma-separated lists, so it occurred to me that a relation and a use of phrase applied to list could be a good fit here.

Town-friendship relates a person to various directions. To town-friend is a verb meaning the town-friendship relation.

To decide what text is the directionville of (d - a direction) (this is directionville):
let t be the printed name of d in title case;
decide on "[t] Directionville";

To say town-friends of (P - a person):
say "[directionville applied to the list of directions that P relates to by the town-friendship relation]";

check requesting the score:
say "Score stuff.";
let l be the list of directions that player relates to by the town-friendship relation;
if number of entries in l > 0:
say "You're sort of friends with [town-friends of player].";
the rule succeeds;

the block thinking rule is not listed in any rulebook.

check thinking:
let L be the list of directions that player relates to by town-friendship relation;
if number of entries in L is 0, say "You're pals with no town. Rats." instead;
say "You're pals with [town-friends of player].";
the rule succeeds;

check waiting:
let D be a random direction;
if player town-friends D, now player does not town-friend D;
else now player town-friends D;
say "Flipping [D].";
2 Likes

Ah, thanks! I think I tried “[d in title case]” first, and it didn’t work. Then elsewhere I found “[printed name of d]” worked, but I never went back and put the two together.

I figured there’d be something simpler, and there was. Thanks very much.

Man, relations! I’ve never used them as much as I felt like I could, and they seem to do neat things when you least expect it. I’ll save this idea for later. It’s a good one.

1 Like

…I realized later the relation was the worst idea there. The part I really wanted was a list of results I could apply a phrase to, and a property (like you had originally) works just fine to make a set-description that yields the list.

A direction can be befriended. A direction is usually not befriended.

To decide what text is the directionville of (d - a direction) (this is directionville):
decide on "[the printed name of d in title case] Directionville";

check requesting the score:
say "Score stuff.";
let L be the list of befriended directions;
if number of entries in L > 0:
say "You're sort of friends with [directionville applied to L].";
the rule succeeds;

the block thinking rule is not listed in any rulebook.

check thinking:
let L be the list of befriended directions;
if number of entries in L is 0, say "You're pals with no town. Rats." instead;
say "You're pals with [directionville applied to L].";
the rule succeeds;

check waiting:
let D be a random direction;
if D is befriended, now D is not befriended;
else now D is befriended;
say "Flipping [D].";