I’ve just started learning Inform 7 and I’m currently trying to get a basic puzzle involving lighting a match and obtaining light.
At the moment I want the room descriptions message to say:
when a light source(which is a kind of thing) is lit, then say a message “[light source] provide a dim light”
rest of the room description.
This is what I have but it isn’t working:
Before printing room description when a light source is lit:
say "The [light source] gives light to the room.".
The first problem is that Inform doesn’t know what you mean by “printing room description”. It’s perfectly logical English, but it’s not the name of any specific routine Inform knows about. In this particular case, the routine you’re looking for is probably the “looking” action:Before looking when the location contains a lit thing (called the light source):
say "[The light source] gives light to the room.".But this prints the message above the room title, which is maybe not what you want. If you want to print it below the title, but before the room description, the easy way is to just include it in the room description:
The Department of Mysteries is a room. "[A random lit thing in the location] gives light to the room.[paragraph break]The Department of Mysteries stretches ahead of you, rows upon rows of glass baubles whispering forgotten secrets."
This works because, if you see the room description, there is light by definition. This does require you paste the message at the beginning of the description of every dark room; but that’s little bother.
(Or, if you want to get fancy, you could do it automatically by doing some messy stuff with rulebooks:[code]This is the describe light source rule:
if the location contains a lit thing (called the light source), say “[The light source] gives light to the room.”
The describe light source rule is listed before the room description body text rule in the carry out looking rules.[/code]…but while Inform’s rulebook-based design is pure genius and will make unicorns come out of the forest to carry you away to Zarf’s magical mind, you might not feel like tackling all that just yet! If you do, it’s Chapter 19 in the manual.)
The other problem with your original code, which I’ve conveniently resolved in the examples above, is that Inform doesn’t know what a “light source” is. Again, it’s perfectly reasonable English, but it’s not the name of any specific concept in Inform’s world. Instead, you can refer to a light source by its properties - “a lit thing”, i.e. a thing that is marked “lit”. Then we give it a temporary name ("(called the light source)") so Inform knows that, the next time we refer to “the light source”, we mean the specific lit thing Inform found when it checked this condition. Section 8.15 in the manual gives more examples.
There’s a few things you can do. One is to start running your game (without the part that’s not working) and type “rules” at the command prompt. Then do whatever action whose rules you want to find out about. (Spoilered for excessive length.)
That’s what would tell you that what you’re looking for for prevtenet’s second solution is the “room description body text rule.”
Or, if you want to find out about “before looking” and like that, you can do the same thing with “actions” instead of “rules”:
You can also use the Index tab in the Inform application, which lists the actions under the Actions tab, and if you click on the magnifying glass next to one of them, gives a lot more detail including the rules that apply to it. (Including any rules you’ve written yourself.)
There’s also a third kind of routine you can fiddle with - “activities”. These are mostly lower-level things like “printing the name of” or “printing a refusal to act in the dark”; Chapter 18 in the manual has a list.