How to Create A Password to Unlock A Safe?

Hello guys!

I’m attempting to create a safe, those microwave-openable types and not those dial types, that require an input on a keypad to make it open. For example, one would type ‘type 123456 on keypad’ to unlock the safe.

Is there anyway to implement the safe? Thanks for reading! :smiley:

Have you tried Puzzle Boxes?

Understand "type [text] on/into [something]" as setting it to.

Instead of setting the safe to "123456":
    say "The safe whirrs for a moment, then swings open.";
    now the safe is unlocked;
    now the safe is open.

Instead of setting the safe to a topic:
    say "The safe beeps softly and remains locked."

This will also allow things like “set safe to 123456”, which would be a reasonable command if it were a dial safe. Better to catch more inputs even if they aren’t entirely correct.

EDIT: Oh also, just in case this was part of your question:

The Closet is a room. A safe is fixed in place in the closet. A priceless diamond is in the safe. The safe is closed and locked.
Instead of opening the locked safe:
    say "It's locked. You need to type in the combination to open it."
Instead of unlocking the locked safe with something:
    try opening the safe.
Instead of closing the open safe:
    say "You slam the door shut and the safe whirrs as it locks itself again.";
    now the safe is closed;
    now the safe is locked.
Instead of locking the open safe with something:
    try closing the safe.

Here’s a more complicated implementation that includes keypads as separately implemented things and makes a new action instead of using the built-in “setting it to” action, applying to a number rather than a text. I made keypads into a kind, which might not be what you need–you could write your rules much more specifically if you only have one keypad. Also, um, for some reason when I read what you said I thought it was actually a microwave.

Anyway, the important things are the way that I defined the action (you need to say “typing it on” so you can later say things like “Instead of typing 123456 on the microwave’s keypad”) and the fact that the number goes in “the number understood” and the keypad goes in “the second noun” even though there’s no first noun. I included some friendlinesses like redirecting typing on the microwave to the keypad but there could be more (for instance, refusing “UNLOCK MICROWAVE” with a message that they have to use the keypad, and providing a helpful message when the player types something that isn’t a number).

[code]Typing it on is an action applying to one number and one thing. Understand “type [number] on [something]” as typing it on.

A keypad is a kind of thing. The description of a keypad is usually “To enter a passcode on the typepad, say ‘type (number) on [item described].’”

A keypad has a number called the code. A keypad has a thing called the associated lock. [This implementation assumes that keypads always are used to unlock things. If we wanted to get complicated we could give every keypad a rule, which would be an effect that would happen when you enter the code–and which could be “now the microwave is unlocked,” or it could be something more complicated.]

Before typing when the second noun is not a keypad and the second noun incorporates a keypad (called real target):
try typing the number understood on the real target instead. [So we don’t give an unhelpful message for “Type 123 on microwave”; we just redirect it to the keypad.]

Check typing when the second noun is not a keypad: say “You can’t type a number on that.” instead.

Check typing something on a keypad (called target) when the number understood is less than 10 and the code of the target is not less than 10:
say “Don’t try to type one digit at a time; just type in the whole code.” instead.

Check typing when the number understood is not the code of the second noun: say “[The second noun] beeps irritatingly and refuses to do anything. Must have been the wrong code.” instead.

Check typing when the associated lock of the second noun is not locked: [this should only be reached when you’ve typed the right code]
say “[The associated lock of the second noun] is already unlocked.” instead.

Carry out typing: [because of the check rules this should only fire when we’ve typed the correct code on a keypad whose associated lock is unlocked]
now the associated lock of the second noun is unlocked.

Report typing: [this also will only fire when the carry out rule has fired]
say “[The associated lock of the second noun] unlocks with a click.”

[and a scenario]
Kitchen is a room. A microwave oven is a locked transparent container in the kitchen. The description of the microwave oven is “It has a keypad–but where it ordinarily would say ‘START’ it says ‘UNLOCK.’ Strange. Perhaps you have to type a code on the keypad?”

The microwave’s keypad is a keypad, part of the microwave oven. The code of the microwave’s keypad is 123456. The associated lock of the microwave’s keypad is the microwave oven. Understand “microwave keypad” as the microwave’s keypad.

A gold nugget is in the microwave. The description of the gold nugget is “[if the gold nugget is in the microwave]Who put a gold nugget in the microwave? Didn’t they see American Hustle?[otherwise]It’s a valuable gold nugget.[end if]”.

[and a clue]
The player carries a note. The description of the note is "It says 'Congratulations, you took inventory! The code of the microwave oven is .'"

Thanks so much for the help, guys! Looking at the codes, I realize how little I know about Inform and I’ll certainly learn more about it soon enough!

I attempted to put the code in, but this is what I got:

The grammar you give in ‘Understand “enter [a number] into/in/on [something]” and “type [a number] into/in/on [something]” as setting it to’ is not compatible with the Setting it to action (defined as ‘applying to one thing and one topic’) - the thing you suggest this action should act on is not an object at all.

Any help on this?

It looks like you’re trying to combine pieces of Matt (W)'s code and mine. I repurposed the existing “setting it to” action, which applies to text, hence the “[text]” token. He created a new action, which applies to a number, hence the “[number]” token. Either approach works, but in this case you need to pick one and stick with it.

Also notice that the two actions go in opposite order–for setting it to the thing comes first and the text comes second, for the typing it on action I created the number comes first and the thing comes second.