i7 coding help-- open, door!

Hi,

New to board, new to IF, new to I7, new new new…

Writing my first game-- I want the player to not be able to leave the room unless they’re carrying a certain book. I locked the door and used the kind of code you’d use for a key, but it’s inelegant (‘you unlock the door with the book’) and for some reason I’ve done something wrong between my 2am obsession and my morning coffee that made the whole thing collapse.

Any advice? Also, is there a way to work around the “the door is locked” so it says something like “you shouldn’t leave without your book” or something a little less weird? Though I shouldn’t be picking at aesthetics until I’ve mastered practicality, I suppose.

I’m not sure if this is the kind of question that should go here, but any help would be appreciated.

Thanks in advance,
…riley

It’d be easier if you didn’t actually lock the door at all. You can just stop the player from opening it when they don’t have the book.

Instead of opening the library door when the player is not carrying the encyclopedia: say "You shouldn't leave without your book."

First of all, welcome! :slight_smile:

Secondly, as a personal observation, I’ve found that a fixation on aesthetics often leads me off track, but to not focus on it is borderline impossible. It’s just a question of how much effort you’re willing to expend and how to keep track of all the consequences.

Thirdly, to your exact question, arguably the simplest way to do so is by way of the “instead of going…” rule.

Instead of going when the player does not have the book: say "You shouldn't leave without your book."

Of course, this message will fire when you try going in any direction, and it’s going to happen everywhere. Therefore, on the assumption that the room you want the book to be found in is called “the Library”:

Instead of going from the Library when the player does not have the book: say "You shouldn't leave without your book".

There certainly far more elegant ways of doing it (there are reasons for why experienced writers caution against overuse of Instead rules), but this one should do the trick.

If you ask me, that’s about as elegant as it gets. Instead rules are made for special cases, and this looks like a special case to me. Plus, it’s brief and perfectly readable.