Making a passcode to unlock an object (Inform 7)

I’m trying to make an object that unlocks based on a passcode. However, I have no idea how I’d go about doing it at all, really.

Basically, I want it to accept a code, only in relation to an object (or group of objects, unrelated of course) that are made for it, and I want it to check to make sure that the code is correct.

For example, say you say “enter 1 2 3”. I want it to check to see that the actual code is, in fact, “1 2 3”, except maybe something closer to “one two three”, as I’d be using words.

Thanks in advance. :slight_smile:

You need to create a new action, say “passunlocking”, with grammar that accepts text, e.g., ‘Understand “enter [text]” as passunlocking.’

Then you can write a check rule that checks whether “the topic understood” matches the text you want the player to match.

(I’m writing this just after I got out of bed and without Inform 7 open, so I might have made a small grammatical mistake. But the principle is the right one.)

Edited due to Matt’s post below.

There’s a recipe for a door that open with a password in this earlier post. (It works on a different principle from Victor’s and may or may not be what you want.)

That should be “the topic understood,” actually.

Alright, so doing that should allow me to create a method to unlock an object through a code? Or is that really possible? It seems like just doing that would force me to have to use a Before opening: / Check opening: or similar to simply emulate the feel of unlocking through a code.

If your object is an openable door or container, you shouldn’t have to write any special before/check opening rules – there are already built-in rules that prevent the player from opening something that’s locked. All you should have to do is write “The brown door is locked.” or “The safe is an openable container. The safe is locked.” in your code, and then write “now the safe is unlocked” at the point in the rule where it actually gets unlocked. (You can see where that happens in the code Felix linked.)

Gotcha. From that knowledge and the post above, I’ll try and figure something out. :slight_smile:

There will be a few things to watch out for: e.g. a passunlocking action probably should only work for doors in scope(!), and this will not automatically happen, if you define the action as just applying to one topic.