Converting text into a room/object

I am trying to figure out how to convert some text into a room, to dynamically move the player around based on an object’s attributes. I’m trying to do something like:

[code]Bedroom is a room. “It is boring”
Ocean is a room. “It is wet”

A book is a kind of thing. A book has some text called a setting. The description of a book is “The book looks like it takes place in the [setting].”

There is a book called Moby Dick in the bedroom. The book has a setting “Ocean”.

Studying is an action applying to one thing. Understand “study [something]” as studying.

Carry out studying:
say “You study [the noun]”; move the player to the setting of the noun.[/code]
But of course you can’t move the player to some text (‘setting of the noun’ has the wrong kind of value: a text rather than an object.)!

I know in this case I could do “A book has a room called setting” and “The book has a setting Ocean”, but my actual use case requires getting/setting text and then traveling accordingly.

Could you go into a bit more detail about the use case? I’m not entirely sure what you’re trying to do here, and why you need to use text rather than using a room as a value.

If you do need to match up some free-form text, which isn’t some predefined room name or value, then you probably want an action applying to a topic rather than to a thing:

Studying is an action applying to one topic. Understand "study [text]" as studying.

Then the text that the player has entered will be stored in the value “the topic understood” (as when you have an action applying to a thing, the thing the player has specified is stored in the value “the noun”). The problem is translating that topic back into the name of a room.

The only use case I can think of for matching free-form text is a case in which the player is allowed to give names that correspond to rooms and then has to enter those names to travel to the rooms. This could probably be accomplished with a table that gets filled in as the player names the rooms and that you check as the player enters the “study” command. But that doesn’t seem like what you have in mind. If you don’t have to dynamically set the names, why not avoid going through text tokens at all?

Yup, that’s (unfortunately?) exactly it. For example, if I could change the name on a sign pointing west and then have the west exit change accordingly.

Hadn’t come across “the topic understood” yet - I’ll check it out, thanks.

Hmmm. Well, I could try to whip up something with a table. But it seems to me that your sign case won’t actually call for free-form text. What happens if I write “Castle Entrance” on the sign but there’s no room called “Castle Entrance”?

For that particular case what I’d do is have one action that understands “write [room] on [sign]” and then write some other actions that intercept similar commands and print graceful failure messages. (One action that understands “write [thing] on [sign]” and another that understands “write [text] on [sign],” both of which print something like “You somehow fail to write this on the sign.”) Then when you’re processing the original action you’ll already be dealing with a room and won’t have to worry about converting the text into the room yourself.

Success! Demo:

[code]Bedroom is a room. “It is boring”
Ocean is a room. “It is wet”
Jungle is a room. “It is hot”

A sign is a kind of thing. A sign has a room called a destination. The description of a sign is “The sign is pointing toward [destination]”.

There is a sign called street sign in the bedroom. The destination of the sign is nowhere.

Writing is an action applying to two things. Understand “write [any room] on [something]” as writing.

Check writing:
if the noun is not a room, say “You somehow fail to write this on the sign.” instead.
Carry out writing:
change the destination of the second noun to noun; say “You wrote on the sign”

Scrawling is an action applying to one topic and one thing. Understand “write [text] on [something]” as scrawling.

Check scrawling:
if the second noun is not a sign, say “Your marker only works on signs.” instead.
Carry out scrawling:
change the destination of the second noun to nothing; say “You wrote on the sign”

Following is an action applying to one thing. Understand “follow [something]” as following.

Check following:
if the noun is not a sign, say “You walk around in circles.” instead.
Check following:
if the destination of the noun is nowhere, say “The sign doesn’t appear to be pointing anywhere.” instead.
Carry out following:
move the player to the destination of the noun[/code]

The multiple-actions tip was definitely the secret sauce, I appreciate it.

Cool! A couple more things:

Make sure to put periods at the end of your descriptive text:

"It is boring."

rather than

"It is boring"

Besides the usual reasons, including the period will make your spacing work better and in some cases may be necessary for Inform to compile your source text. (If I copy the exact text the way you posted it, it won’t compile because Inform can’t tell that that line of code ends at “It is boring”.)

You should also write a case to take care of “write ocean on me” and other examples where the player writes a valid room name on something that isn’t a sign. Another “Check writing” rule like your “Check scrawling” rule would work.

Anyway, glad I could help!