Swap object for object with the same name.


I don’t know if this is possible in Inform 7?

A usual trick in Quest is to swap one object for another e.g. broken radio for fixed radio, but for the player they are both called ‘radio’ - there is the object name that the code uses, and the name that the player sees which can be different. This is particularly useful for NPCs who are in different states e.g. asleep, awake, unhappy, happy etc.

I can get around this by putting conditionals on just one object, but it can get messy if there is a lot going on.


(matt w) #2

The name that the player sees is the printed name property:

The broken radio is a thing. The printed name of the broken radio is "radio". The fixed radio is a thing. The printed name of the fixed radio is "radio".



Thanks, that’s perfect.

Along the same lines, how do I deal with name conflicts between rooms and people/objects.

E.g. I want to put Elves inside The Elves Workshop. Inform doesn’t like it!



I believe you can do the same with rooms–call the room Workshop in your code, then say

The printed name of Workshop is "The Elves' Workshop".

or, if that is the actual name of a container(for the sake of example), do the same, but also make sure that the player can refer to it with the same words by saying

Understand "The" and "Elves" and "Workshop" as the workshop.

Also, in the case where it is a container, you’ll want to clarify, in your code, which one the player means when the player wants to do something with the elves–most likely the player will mean the actual elves (rather than the workshop, if this is a container)–you can include a line saying

Does the player mean doing anything with the elves:  it is very likely.

just to make sure.

That’s the way I understand it, but I’ll defer to the experts (I’m not really one).



That solves my problem. Thank you!


(Andrew Plotkin) #6

If you’re going to swap objects like this, consider this bit of polish:

The broken radio is a thing. The printed name of the broken radio is "radio".
The fixed radio is a thing. The printed name of the fixed radio is "radio".

The fixed radio is in the Kitchen.

Check attacking the fixed radio:
	now the fixed radio is off-stage;
	now the broken radio is in the location;
	set pronouns from the broken radio;
	instead say "You smash the radio. Now it doesn't work."

The line “set pronouns from…” resets “it” to refer to the given object. This allows the player to type



I’m surprised you can’t put Elves into the Elves’ Workshop; this should be possible. You could try declaring them in a different order in your code (sometimes this helps).

If that fails, there is a way of declaring rooms/objects which is slightly clunky, but which makes sure the names are unambiguous:

There is a room called the Elves' Workshop.
There is a thing called some Elves.
The Elves are in the Workshop.

(It’s preferable not to mess around with printed names if you don’t have to, I think.)


(Andrew Plotkin) #8

Personal coding style. I set printed names on practically every Inform object I create.


(matt w) #9

If you do go the printed name route, you don’t need to have “the” or “workshop” understood as the workshop–“workshop” is understood automatically because of the internal object name, and “the” is automatically understood as any noun (that’s not exactly how it works internally, I don’t think, but anyway it doesn’t need an explicit Understand).



If I may add a generalised version of the above, using relations:

The Shack is a room.

Degrading relates one thing to one thing. The verb to degrade to means the degrading relation.

The glass bottle is in the Shack.

The broken glass is nowhere. The indefinite article is "some".

The glass bottle degrades to the broken glass.

Instead of attacking something which degrades to something (called wreckage):
	say "You let your anger loose on [the noun]. It gets smashed, leaving behind [a wreckage].";
	now the noun is nowhere;
	now the wreckage is in the location;
	set pronouns from the wreckage.

(Thanks, Zarf, for the “set the pronouns part!” I didn’t know that one!)

All this gives us: