I’m trying to update an old 6SG0 game to 6M62 which included basic commands for displaying figures. For some reason, when the “display figure” command is nested inside a “To say” command, it displays the image twice in a row, now (it didn’t do this in the old version of inform7).
An NPC is a kind of person.
Alan is an NPC. Alan is in Example Location.
Davis is an NPC. Davis is in Example Location.
The player is Davis.
Figure Alan is the file “alan.jpg”.
The Description of an NPC is usually “[NPCDesc of item described]”.
To say NPCDesc of (X - a person):
display figure alan.
For contrast, if I just write:
Check the player examining Alan:
display figure alan;
Then it works as designed and displays the image only once. I’d much rather use the former method though since it’d save me having to code a ton of “check the player” rules etcetera. Any help is much appreciated
Welcome to the forum
The problem here is that when examining Alan, Inform first expands all the text substitutions silently, without printing anything, in order to checks on the result, before then expanding them all again in order to report the outcome.
Because the DescNPC routine displays a picture rather than printing text, this is not suppressed during the ‘trial run’ and the picture is therefore displayed twice. The same potential problem occurs with any text substitution which changes the game state as well as or instead of printing text.
The trick is to catch the case when the expansion is taking place for the purposes of of examining a substituted text rather than printing it. This can be done with the condition ‘expanding text for comparison purposes’ which is true during silent ‘trial runs’ of text substitution.
The Lab is a room.
An NPC is a kind of person. Alan is an NPC in the Lab. Every NPC has a figure name called picture.
Figure Alan is the file “alan.png”.
The picture of Alan is Figure Alan.
The Description of an NPC is usually “[line break][bold type][item described][roman type][line break][NPCDesc of item described]”.
To say NPCDesc of (X - an NPC):
if not expanding text for comparison purposes:
display the picture of X.
You also can insert [if not expanding text for comparison purposes] as a text expansion instead if you want.
Note that the description must print something in the way of text, even if it’s just a blank space, otherwise when the text is expanded for comparison purposes Inform just detects an empty text and you will get the ‘You see nothing special about Alan.’ response without a picture- which is the whole purpose Inform has in expanding the text without printing it the first time around- it’s checking whether the item has a description set. or not, and if not it prints the default response rather than trying to actually print anything.
Well, that appears to have done it. Thank you very much for the in-depth reply - I don’t know the first thing about what’s happening behind the scenes with inform so this is something I’d never have figured out on my own even if I’d beat my head against it for a week haha
It foxed me for a while the first time I came across it- it’s a rather unexpected behaviour that’s not prominently flagged in the documentation (i.e. not at all).
Indeed, ‘if expanding text for comparison purposes’ is only used once in the whole of the I7 segments of the Standard Rules (although its I6 equivalent is used more often)