Combo locks?

We can’t find a good extension for making combination locks (locks that require entering text or a number to unlock, for example)

Does anyone know where i could find an extension to do this, or have ideas for how to make one? Thanks!

1 Like

I tried writing an extension for this a while ago and found it wasn’t a thing that lent itself well to an extension, 'cause the basics were pretty trivial, but the design choices of how it should behave could go off in all sorts of directions. There wasn’t much that was generic that could be abstracted away.

Here are a couple of examples I wrote at the time.

Lab is a room.

To decide if the sequence of (t - a thing) is complete:
  decide on whether or not the sequence-pointer of t is the number of entries in the sequence of t.

To decide if (v - a value of kind K) is next for (t - a thing):
  let n be the sequence-pointer of t;
  if the sequence of t is complete, now n is 0;
  increment n;
  decide on whether or not (entry n in the sequence of t) is v.

To set (t - a thing) to (v - a value of kind K):
  if v is next for t, increment the sequence-pointer of t;
  else now the sequence-pointer of t is 0.

The safe is a locked container in the lab.
The safe has a list of texts called the sequence.
The safe has a number called the sequence-pointer.
The sequence of the safe is { "2", "4", "2", "9" }.

The block setting it to rule does nothing when the noun is the safe.
carry out setting the safe to:
  set the safe to "[the topic understood]";
  if the sequence of the safe is complete, now the safe is unlocked.

After setting the safe to when the safe was locked and the safe is unlocked:
  say "Thunk. The safe unlocks."

Report setting the safe to: say "Click."
Lab is a room.

The tiles are in the lab. "The tiles are labeled with the letters of the alphabet.".
The tiles have a list of texts called the sequence.
The tiles have a number called the sequence-pointer.
The sequence of the tiles is {"x", "y", "z", "z", "y"}.

Stepping is an action applying to one topic.
stepping action has a text called the setting.
stepping action has a number called the previous sequence pointer.

Setting action variables for stepping:
now the setting is "[the topic understood]";
now the previous sequence pointer is the sequence-pointer of the tiles.

Understand "step on/-- [text]" as stepping.
Carry out stepping when the location is the lab:
    set the tiles to the setting;

After stepping when the location is the lab and the sequence of the tiles is complete:
  say "victoire!"

Report stepping when the location is the lab:
  if the sequence-pointer of the tiles > the previous sequence pointer, say "[We]['re] getting warmer.";
  else say "Ice cold."
3 Likes

This should at least be helpful to look at for our own games, and maybe we’ll make an extension that fits our personal use cases! Thanks <3

1 Like

I’ve also used Writing With Inform’s examples several times:

The Addams Wine Cellar is a room. It contains a closed lockable locked container called a safe.

The safe has a list of numbers called the current combination.

The safe has a list of numbers called the true combination. The true combination of the safe is {2, 10, 11}.

Understand "set [something] to [a number]" as setting it numerically to. Setting it numerically to is an action applying to one thing and one number.

Instead of examining the safe:
    if the number of entries in the current combination of the safe is 0,
        say "You haven't dialed the safe to any combination yet.";
    otherwise say "You have dialed the safe to [the current combination of the safe].".

Check setting something numerically to (this is the block setting numerically rule):
    say "[The noun] cannot be set."

Instead of setting the safe numerically to the number understood:
    truncate the current combination of the safe to the last 2 entries;
    add the number understood to the current combination of the safe;
    if the safe is locked and the current combination of the safe is the true combination of the safe:
        say "You dial [the number understood], and [the safe] gives a joyous CLICK.";
        now the safe is unlocked;
    otherwise if safe is unlocked and the safe is closed and the current combination of the safe is not the true combination of the safe:
        say "You spin the dial, and [the safe] snicks locked.";
        now the safe is locked;
    otherwise:
        say "You dial [the number understood] on the safe."

Test me with "x safe / set safe to 10 / x safe / set safe to 29 / x safe / set safe to 2 / x safe / set safe to 10 / x safe / set safe to 11 / open safe / set safe to 14 / close safe / set safe to 15 / open safe".

or

The Vault is a room. "Snug yet paranoid, this represents the state of the art in cheerless security." The Safe is here. "A mammoth safe, with a dial which can spin to any number, has pride of place. It must weigh about the same as a small car, so don't get any ideas." Instead of opening the safe, say "The safe opens only when turned to the correct combination."

In the Safe is a silver florin. The Safe is closed and fixed in place. Understand "dial" as the Safe.

Spinning it to is an action applying to one thing and one number. Check spinning it to: if the noun is not the Safe, say "[The noun] does not spin." instead. Report spinning it to: say "Click! and nothing else happens."

Understand "spin [something] to [a number]" as spinning it to.

After spinning the closed Safe to 1384: now the Safe is open; say "Clonk! and the safe door swings slowly open, revealing [a list of things in the Safe]."

Test me with "open safe / spin safe to 1131 / open safe / spin safe to 1384 / x safe / get florin".
3 Likes