The most important effect that I am trying to achieve is that a player cannot read a room description if the lighting is “notlit,” e.g. not illuminated by the three sources of light that I have outlined in the game (the sun for sunlit, a lantern for lanternlit, and a torch for torchlit).
Here is some code that should allow me to illustrate my point:
Lighting is a kind of value. The lightings are sunlit, lanternlit, torchlit, and notlit. A room has lighting. A room is usually notlit.
A lantern is a kind of thing. A lantern is scenery. A lantern can be lit or unlit. A lantern is usually unlit. There is a lit lantern in Long Hallway.
[irrelevant lighting code]
Every turn while the location of the player is notlit:
if the player has the torch:
let lightpath be the best route from the location of the player to Long Hallway;
if lightpath is not nothing:
say "You wander around in the darkness and can't seem to find your way. A voice seems to whisper from nowhere: 'go [lightpath].'";
else:
say "The room is completely dark, and you can't seem to find your way.";
else:
if the location of the player is the location of the torch:
say "The room is completely dark. It might be wise to pick up your torch and find the nearest source of light.";
else:
let torchpath be the best route from the location of the player to the location of the torch;
if torchpath is not nothing:
say "It's dangerous to go alone. A voice seems to whisper from nowhere: 'go [torchpath].'";
else:
say "It's dangerous to go alone. You must find your torch if you are to successfully make it out alive.";
I got this pathfinding method from a Reddit post, and it is intended to guide the player back to having a light source, whether that’s finding a lit lantern, or grabbing their torch again from the room they left it in. Here’s a sample transcript of how I want the story to go (the player starts with a lit torch in their inventory)
Sunlit Entrance
Where your journey begins, a cold stone that seems to extend into a long hallway to the north. Here, there’s a large beam of light shining through a glass pane in the ceiling that lights up the entire room.
n
Long Hallway
A long corridor connecting the Entrance of the tomb to the south and what appears to be another room to the north. A lantern hangs on the wall, providing a steady glow to most of the hallway. While you can still see much of the sunlight from the entrance of the tomb, if you go any further into the crypt, light might become a real problem.
drop torch
Dropped.
n
Crypt Entrance
It’s dangerous to go alone. A voice seems to whisper from nowhere: “go south.”
I tried to implement the decide line that you suggested, but the story never seems to access it (I tried to have it “say” something when the lighting was checked but that code never ran). My method is below, maybe my implementation is off?
To decide which lighting is the current lighting of (R - room):
say "test statement";
if R is not sunlit:
if there is a lit lantern in R:
now R is lanternlit;
else if the location of the torch is R:
if the torch is lit:
now R is torchlit;
else:
now R is notlit;
else:
now R is notlit;