# Creating locked vault

Disclaimer : please accept my apologies if my english is not perfect

Hello everyone,

I work now on a project where the players have to open a lock at the end of the game, during which they gather numbers that form the code. I do not know and cannot find how to collect the inputs the player give and verify if they are the good ones and in the good order to then display the final result.

How can I store an input into a variable and then check if it is correct, knowing that there are six numbers to collect ?

I work with Harlowe 3.1

Thanks a lot for your help

2 Likes

Iâ€™m not familiar with Harlowe, but could you store the six parts as a series of strings? Or, if the code is the same every time, could you store it as a series of flags indicating which pieces have been found?

1 Like

You can approach this with different philosophies of interaction. The easiest is the player hits a passage where they find the code to the vault. That sets a variable \$knowsvaultcode=true. The next time they approach the vault if \$knowsvaultcode=true then the player gets a new link in that passage â€śUse the code to unlock the vault.â€ť which appears only when the variable is true.

You could make this more complicated by requiring the player to find six numbers/codes and setting a series of variables \$knowsvaultdigit1, \$knowsvaultdigit2â€¦(etc) and all six must be true before they get the â€śOpen the vault.â€ť link.

One suggestion with this is you want to encourage the player and set up their expectation of what they need to do by varying the text in the vault lock passage so it lets them know exactly how far along they are in the puzzle:

Youâ€™re in front of the vault door. Itâ€™s locked with a six-digit combination.
You know the first digit is 5 since you got the note in the library.
You donâ€™t know the second digit.
You donâ€™t know the third digit.
You know the fourth digit is 8 since you saw it scrawled on the mirror.
You donâ€™t know the fifth digit.
You know the sixth digit is 2 since you did all that math in the dining room.

In this example, each line varies whether each variable is true or not. When all six variables are set, they get an extra link to [open the vault].

You could of course, through Twineâ€™s different choice/input methods, devise some way for the player to manually enter the code - either by typing it in, or by cycling links for each numberâ€¦ I personally have found that things go much more smoothly by directing it so the player and the game both know when a puzzle is solved and there are less fiddly hoops to jump through. The game and the player both know theyâ€™ve solved it so narration saves you from coding an actual lock to fiddle with.

I use AXMA which is kind of like Twine, but you will need to adjust the code for your flavor of Harlowe - this is just for example:

How I'd do this in Axma with one code variable...
``````You're standing in front of a locked vault.
<<if \$knowsvaultcode eq true>>
You found the vault code in the library, so you can enter it now.
[[Enter the vault code 290324.|inside vault]]
<<else>>
The vault needs a six digit code. You'll need to find that before you can open it.
<<endif>>
``````
How I'd do it with a separated 2 digit combination in Axma
``````You're standing in front of a locked vault.
<<if \$knowsdigit1 eq true and \$knowsdigit2 eq true>>
You know the code is 25 since you found both clues!
[[Enter the vault code 25.|inside vault]]
<<else>>
The vault needs a two digit code. You'll need to find that before you can open it.
<<if \$knowsdigit1 eq true>>
You know the first digit is a 2.
<<endif>>
<<if \$knowsdigit2 eq true>>
You know the second digit is a 5.
<<endif>>
<<endif>>
``````
2 Likes

Thank you for your kind help, I see things a little bit clearer now

Then, is it possible to set a variable value to an input ? Like I tried this, but it does not work :
`(set: \$val1 to <input type="text" />)`

Because if I can do so, then I can something like :

`(if: \$val1 is 2 && \$val2 is 3)[Open vault]`

One part of the game is physical : the players have to find digits inside a building, note them down and then enter the code

Thanks again !

1 Like

Iâ€™m not familiar with the exact code format for Twine to input numbers, but it should be possible. And I believe thereâ€™s a way to concatenate variables to match up with what a player puts in to check whether it matches Hopefully someone will chime in with specifics.

Hi again,
Thank you all for your help, I have found a solution using pop-ups and it works just fine

``````(set: \$letter1 to (prompt: "Letter 1:", ""))
(set: \$letter2 to (prompt: "Letter 2:", ""))
(set: \$letter3 to (prompt: "Letter 3:", ""))
(set: \$letter4 to (prompt: "Letter 4:", ""))

Code : \$letter1 \$letter2 \$letter3 \$letter4.

[[If nothing is diplayed, the numbers are wrong. Try agin  ! ->Enter code]]

{
(if: \$letter1 is "M" or "m" and \$letter2 is "U" or "u" and \$letter3 is "S" or "s" and \$letter4 is "E" or "e")[[Open vault]]

}
``````

Thank you all agin

2 Likes

Three other options you could use, these only prompt once and not multiple times to enter and check the code.

Text code:

``````(set: \$code to (prompt: "Enter the code:", ""))
(set: \$code to (uppercase: \$code))
(if: \$code is "MUSE")[The code is correct.](else:)[The code is wrong.]
``````

Number Code:

``````(set: \$code to (prompt: "Enter the code:", ""))
(if: \$code is "123456")[The code is correct.](else:)[The code is wrong.]
``````

The last option could be to use some or all the clues as random numbers created at the beginning of the gameâ€¦

``````(set: \$clue1 to (random: 0,9))
(set: \$clue2 to (random: 0,9))
(set: \$clue3 to (random: 0,9))
(set: \$clue4 to (random: 0,9))
(set: \$clue5 to (random: 0,9))
(set: \$clue6 to (random: 0,9))
(set: \$correctcode to (str: \$clue1)+(str: \$clue2)+(str: \$clue3)+(str: \$clue4)+(str: \$clue5)+(str: \$clue6))
``````

and then have them checked at the end.

``````(set: \$code to (prompt: "Enter the code:", ""))
(if: \$code is \$correctcode)[The code is correct.](else:)[The code is wrong.]
``````