Newbie question around changing the status of rooms (dark/light)

I just went through the Quick Start Guide of learning Inform 7, by Carolyn VanEseltine

Specifically the lesson on light and dark. https://web.archive.org/web/20190131112259/http://www.sibylmoon.com/welcome-to-adventure-lesson-9-darkness-and-the-lamp

I have been writing the Inform Code alongside and running it, to make sure I understand the concepts. After running what I had from this lesson, I was able to get the lamp, light it and go into the dark area, but I still ‘broke every bone.’

Am I right in assuming that there needs to be an if/then statement added to the section about a 1/4 chance of dying?

As in, although I’ve got a lamp on, the room is still classified as ‘dark’ overall. The room is lit, but it’s still dangerous, right?

Like: (rough code, not tested)

if lamp is lit:
   continue the action;
else:
   if a 1 in 4 chance succeeds:
   say "you fell into a pit";
end the story saying "ow".

I’m going to test this myself but assuming I’m getting something wrong also wanted to get some leads on the right path!

From checking out the chapter excerpt, this looks like the code for falling into the pit:

After going when the location is a dark room:
    if a random chance of 1 in 4 succeeds:
        say “You fell into a pit and broke every bone in your body!”;
        end the story saying “Ow.”;
    else:
        continue the action.

So yeah, that one in four chance will fire regardless of whether or not there’s a lit lamp around allowing the player to see – as you say, the room remains dark (though note that the opposite of a dark room is a “lighted” room, “lit” is for objects that provide light). And yes, adding an additional condition to the rule would be the way to go.

The rough code you posted wouldn’t quite get you there, though – in particular, if the lamp is lit but has been dropped in some other location, the condition will still fire and protect the player from falling into a pit, which I don’t think is the intended behavior (the exact details of how Inform determines whether a lit object illuminates a location can be pretty complex – what if the lamp is lit and the player carries it, but it’s in an opaque container? – since you’re just learning the language, though a simple way to approximate things is to just check if the location “encloses” the lamp, which covers both the case where the lamp’s in the location or the player’s carrying it).

But yeah, you’re pretty much on the right track – good luck continuing to dig into Inform!

1 Like

I think you can change this to
After going when there is not sufficient light:

If the text has a declaration The Cavern is a dark room it remains true even when a light source is inside, but the room can “have sufficient light” via a portable light source.

See: 12.19. Changing visibility

1 Like

Thank you for the notes and ideas!

(And for letting me know I’m on the right track, not to mention gesturing towards the complexity of the situation!)

I’m going to experiment with solving this issue and repost the solution here if I can figure it out.

I’m grateful to Carolyn for creating the quick-start guide and I’m also grateful that it’s bare-bones enough to expose these sorts of use-cases and questions! (I should note that Carolyn often notes that a particular mechanic being explored is just the tip of the iceberg.)

1 Like

Thank you for this! I’ll give it a try!

2 Likes

The ‘official’ means for testing whether the player is in darkness is simply ‘if in darkness’- which has the merit that it takes account without effort of all the complex rules Inform uses to judge light and dark.

So:

After going when in darkness: say "Aaarggh!"; continue the action.

(replace 'say “Aaarggh!” ’ with the code you want to run).
The ‘continue the action’ is to ensure that the going action rolls forward to the Report stage and that we therefore also get the usual announcement of Darkness. To avoid that happening, omit the ‘continue the action.’

3 Likes