How to change the description of a room if a specific item is in the inventory of the player. How to stop the player from entering a room if a hasn't got a specific item

Pretty much what the title says. Here is my code:

Cave is south of Field. "A dark, low cave that continues east. You need a lit torch to continue further."
Further in the Cave is a dark room. It is east of Cave. "You have walked in the home of a Troll! You can not flee and need to fight it.".

I would like the description of the room ‘Cave’ to be “A dark, low cave that continues east.” if the player already has the item ‘flaming torch’. I’d also like to have the room ‘Further in the Cave’ to not be accesible if the player hasn’t got the flaming torch. Can anyone help me?

Cave is south of Field. "A dark, low cave that continues east. [unless player holds the flaming torch] You need a lit torch to continue further."

See documentation §5.6. Text with variations

1 Like
Instead of going east in Cave when the player does not hold the flaming torch:
	say "It's too dark to go blundering deeper into the dark cave without light.".

See §7.13. Going from, going to

1 Like

Or you might like to use the built-in representations of light and darkness which would make life easier if a light source mattered elsewhere.

Cave is a room. "A dark, low cave that continues east." The flaming torch is a lit thing in Cave.

Further in the Cave is a dark room. It is east of Cave. "You have walked in the home of a Troll! You can not flee and need to fight it."

Check going to a dark room:
      if the player is not carrying a lit thing, say "You'll need a light source to continue further." instead.

See Writing in Inform 3.15 and 18.18-18.22 and The Recipe Book 3.7.