Safe combinations : Works, but script makes player stuck and cannot move out of room!

I have a 6 numerical code of numbers for the player to type to open a safe, but how do I create a script that allows the player to type ANY 6 digit code and have a "wrong code answer". I don't want to have to make a script with every single combination possibility listed!

(edited slightly to tidy up the code)

There's a few different ways to do it. You could have a command with a pattern like enter code #text#, so the player can enter whatever they want. Then your script would look something like:

if (not IsInt(text)) {
  msg ("The safe only has number buttons. Try entering a number.")
else if (LengthOf(text) > 6) {
  msg ("The safe clicks after you enter the first six digits. It looks like it won't take any more.")
  text = Left (text, 6)
if (LengthOf(text) < 6) {
  msg ("The safe doesn't react. Maybe you didn't enter enough digits,")
else if (text = "622414") {
  msg ("After you enter the code, the safe unlocks!")
  safe.locked = false
else {
  msg ("Your code doesn't seem to be right.")

That's all the options, using else to cover any cases that aren't already listed.

Or you could use a single command and ask the player to type a code using the get input command. If you do that method, the code they entered will be in the variable result rather than text, but you will still be able to check whether it's right or not.

Could you please explain this again using the context of the online editor pop up menus. I am struggling to interpret exactly how make a script in the way you have explained it using actual code. I don't see code on my screen, only menus!

The "if" script pop up menu option has multiple commands to click on including "expression". I have only mastered most of the listed options and never used the "expression" command.

Are you able to explain via the menu pop up method please?

Yes, you'll want to be using expression. Expression is really more of a setting than a command? I don't know.
Have you already copy-pasted mrangel's code?

There is nowhere to paste a script of this size.

The pop up menus have to be activated a word or command at a time. Some of the commands listed in the code supplied above are not recognized in the pop up menus.

e.g. safe.locked = false simply does not exist in the pop up menu options.

I am using online QUEST.

Wherever you enter a script, there is a button that says "Code View".

You can paste code into there, and then press "OK" to see what it looks like in the GUI editor.
Even if you prefer working with the GUI, code view is still useful because it lets you copy and paste code to show other people.

Okay so assuming you have a large chunk of code in your game preventing you from using code view, you still copy mrangel's code.
Just for reference, code view is right next to "add script", or paste if you are copying code...
So what you do is get "if" there, and pull up "expression", and type word for word copy what mrangel has in those parentheses there without copying the parentheses. According to mrangel's code you also need to post a message and to add a variable or an attribute.
Please let us know if this works.

I found the "code view" at the bottom of the script page and pasted the whole code in, but there was no "command pattern" text, so I put in the number 622414 as the solution code listed. Also I tested it with "regular expression" as same number 622414 and get the same error below...

Code fails with error : Error running script : Error compiling expression 'not IsInt(text)' : unknown object or variable 'text'

When I see this code, I don't see how it is allowing players to type in any wrong 6 digit random number ! Because all the random numbers I typed in just gave the usual "I don't understand your command". The whole point I am trying to solve is that players will get a reply of "incorrect code" to a random 6 digit number and only get a correct open safe if they type the exact 6 digit code.

mrangle can correct me if I'm wrong, but I believe the command pattern should read enter code #text# in order to work with his code. The command pattern is what Quest is expecting the player to type in.

I suggested that command having the command pattern enter code #text#, which is simple enough to do. Then the player can type "enter code 622414" to open the safe. A pattern like this tells Quest what the player should type; and the special word #text# means that the player can enter anything there, and what they typed will be put in the variable named text.

If you want to let the player just type the code, then you would want to use something like: ^(enter *|code *|(?=\S*\d\S*$))+(?<text>.+)$ (which is a regular expression. This way is more complex to understand, but I think this should let the player type in the text with or without the instruction "enter code". If they don't type "enter code", then it will match any command including a number. (So if they spell a different command wrong, the game doesn't think they're trying to enter the code).

Ok, now I'm thinking I need to read more thoroughly about regular expressions. It looks a bit to me like your cat walked across the keyboard. lol

It looks a bit to me like your cat walked across the keyboard. lol

They can get complicated; that's why I don't normally recommend them for beginners.

Thank you so much "everyone" for your help : I had one thing I still needed and I sussed out it was the "if expression : LengthOf(text) = 6" I was desperate that the player could have an answer for any number of typing EXACTLY 6 digits, but the WRONG 6 digits. This works now. CHEERS!

Here is my explanation to help (non-programmers) on how this works:

I have a "success script" for the correct code typed in with message and sound effects. Players type a specific 6 digit code to open a safe (e.g.) 491031

MY PROBLEM : How to make another script to tell the player when they type the WRONG 6 digit safe code in.

I want a reply for each of these that a player may type :

  1. anything the player types of any length over 6 digits long or even a mix of letters as well
  2. anything the player types lower than 6 digits
  3. anything the player types that is EXACTLY a 6 digit number, but is WRONG

Command Pattern : #text#

if expression : not IsInt(text)
print message : You need to type ONLY six numbers!

if expression : LengthOf(text) < 6
print message : You need to type six numbers.

if expression : LengthOf(text) = 6
print message : That is not the correct 6 digit code.

Tested script and it worked fine.... JUST ONE MAJOR PROBLEM : Player is stuck in room where safe is and cannot type a direction to leave due to the script #text# declaring any text will be e.g. safe not open

So I assume to get out of being stuck in this room (unless type correct code) NO MATTER WHAT A PERSON TYPES... I need to add an acceptable new script of a direction command and send the player out of the room!

BUT THERE IS NO SCRIPT OPTION to move a player vai a script into another room. I cannot create a south or s command and force the player out of room! So the #text# doesn't work and locks player in a room unless they complete the task! NOT GOOD!

Player is stuck in room where safe is and cannot type a direction to leave due to the script #text# declaring any text will be e.g. safe not open

The obvious solution would be to use a pattern like enter code #text#, so that if the player doesn't type those words, the game doesn't assume it's a code.

I thought you might want them to be able to just enter the code, which is why I suggested the regular expression pattern ^(enter *|code *|(?=\S*\d\S*$))+(?<text>.+)$, which accepts enter #text#, or code #text#, or enter code #text# - it will also accept a code typed on its own, but only if the code contains a number and no spaces (which would prevent it matching "north")

I suggested an alternative solution in your other thread.

Log in to post a reply.