Referencing text indirectly and passing it to an action

tl;dr – I’m trying to create an action that takes text as a parameter within a try, but can’t figure out how.

I’m trying to reference a text entity within a “try” clause. Basically, I want to to attach text to something - originally it was a table, but I have the same problem with properties.

The smallest reproduction I’ve been able to make is as follows:

A checklist is a kind of portable thing. A checklist has a list of texts called items.

Adding it to is an action applying to one topic and one thing.
Understand "add [text] to [something]" as adding it to.

Carry out adding it to:
	add the topic understood to the items of the second noun;

A thing has a text called the caption.

The garage is a room.
In the garage is a pen.
The caption of the pen is "Priscilla's Pen".

The player is holding a checklist called the paper.

Before dropping something (called Obj):
	let E be the caption of Obj;
	try adding E to the paper.

This won’t compile, because:

You wrote ‘try adding E to the paper’ , but ‘adding E to the paper’ is not an action I can try. This looks as if it might be because it contains something of the wrong kind.

It then suggests it’s looking for a topic, so I change it to “has a topic called the caption” and it compiles, but fails when I drop something:

*** Run-time problem P39: Attempt to say a snippet value which is currently invalid: words 0 to -1

The table version does this:

Before dropping something (called Obj):
	if Obj is an obj listed in the Table of Stuff:		
		try adding the topic entry to the paper.
Table of Stuff
obj	topic
pen	"Priscilla"

But has the same failures (if the column is not called “topic” then it’s just text and won’t compile, if it’s called topic it crashes. )

I’ve basically spent a day looking for various ways around this. What am I missing, please?

The trick is, there are three kinds of “text-like” things in I7.

“Text” is exactly what it sounds like: text, sometimes with substitutions in it.

“Snippets” are parts of the player’s command. Internally, a snippet means something like “three words, starting at word five”. When an action applies to a “topic”, the “topic understood” will actually be a snippet. (“The player’s command” is also a snippet, one that contains the whole thing.)

“Topics” are parsing routines, rules like “a/the/some/-- person/people”. The only thing you can do with a topic is compare something against it: you can’t say a topic, for example, because should that topic print as “a person” or “the people” or what?

And, crucially, you can’t use text variables in “try” phrases that expect snippets. It’s just an unfortunate limitation of the engine. You can hack around it:

To attempt to add (T - text) to (obj - a thing):
    let temporary storage be the substituted form of "[the player's command]";
    change the text of the player's command to T;
    try adding the player's command to the obj;
    change the text of the player's command to temporary storage.

(Note: untested as of yet.)

1 Like

Do you need to go through the adding action? If you just say

add E to the items of the second noun;

…you wouldn’t get tangled up with snippets and topics.


The problem with direct access is that the game is pretty big, and I’m trying to create reusable components. This layer of indirection is useful in keeping the gameplay interactions from knowing the internal details of the various interactive devices.

That said, maybe I’ve spent too much time on this one, although Daniel’s explanation is useful for my understanding if nothing else; I’ll try it out and report back. Thanks for the replies!

The try... command is for causing actions to be performed in the model world, but (as zarf says) it’s not clear that you really need or want this. Do you want the rest of the model world to react to the action in some way? Do you want to take advantage of action success history?

If not, and you’re just looking for encapsulation, you can achieve that via phrases. For example:

To record (T - text) in/on (C - checklist):
	add T to items of C.

Before dropping something (called Obj):
	record caption of Obj on paper.

A phrase is pretty much the I7 version of a function.


I try to never use text if possible. If you have a limited number of items that might be written on the checklist, I would use objects rather than text.

This is my suggestion as well.

Inform’s topics are really meant only for matching parts of the player’s command. Snippets are meant only to be used as the result of a topic match. Passing them around in your code is iffy at best. It’s best to move as quickly as possible to other types (text, object, number) and do most of your work with those.


Wow. I feel a little stupid for having missed defining my own phrases. I have a 20K word game file with another dozen or so of my own extensions, and I’ve apparently never created a new phrase.

I’m a software engineer by day, and I’ve learned many programming languages over the years, but this one has stretched my brain more than most (mostly in a good way).

Anyway, this seems like it will let me do what I’m looking for. Thanks!