Customize "Unlock" Command

Hello, all! I apologize for what is probably a very easy question, but I have dug around through all of the resources that I know of for an answer to my problem, and, unfortunately, I am coming up empty. The last time I have touched code was BASIC back in 1985, so I'm kind of stuck using the GUI. I am trying to make an IF version of a real world escape room that I have designed, and so far I've gotten around a few hurdles, and it's been a fun ride.

Yet for some reason I seem unable to manipulate the "UNLOCK" command.

Here is what I am attempting to do: As this is an escape room, there will be some boxes with combinations on them. I have used the forums and guides to figure that part out, and I even added a script checking if the player has found the clue that will give them the code (I just figured object flags would be fine for that part). So now, whenever the player "LOOK"s at the box in its original state, they get one of two responses - if they found the clue then they can immediately attempt the combo; if they haven't found the clue yet then they have the option of guessing. I put this all into a function for ease of use, and it works perfectly fine.

That all being said... I have no idea how to make this script work for when the player types "UNLOCK BOX". Right now it only works for "LOOK AT BOX". I imagine that this is a simple fix that I am overlooking, but for the life of me I do not know how to make the "UNLOCK" command for this object alone call my custom function.

What I've done so far is mark the box as a lockable container with 1 key needed to unlock. I humorously discovered that if the number of keys was 0 then the player could simply type "UNLOCK BOX" and poof, lock bypassed! But aside from that, I don't know what else I can do with the "lock" portion of the container tab.

Any insight or advice would be greatly appreciated. Thank you for your time!


On the 'verbs' tab for the box, create a verb named "unlock". Give it a script, and it will be run when the player types "unlock box".

The 'lock' section on the container tab sets this verb to a script that counts keys; don't use it unless you want the box to be unlockable with a key.


Thank you so much, mrangel! I now feel that I am only partly dumb. I did attempt what you mentioned, but I was doing so in the web editor, which would only return the "verb already exists" alert. I attempted this in the program editor and it is now working fine, as you said it would.

That said... I feel like I've already put a lot of work into this on the web editor, and I don't think there is a way to change between the two. I suppose this means that if I want this game to work the way I envision, I have to start over from the program editor.

Oh well, that's just more practice I suppose. :) Thank you again!


You should be able to download a game from the web editor to continue editing it offline, but unfortunately this seems to be one way.

The issue "verb already exists" is odd. As far as I can tell, when you set an object to be lockable on the container tab, it creates the "unlock" verb, but does not list it on the verbs tab. This is a problem if you want to change the verb later.

You might be able to get around this by making sure that the "lockable" type is not set before attempting to create the verb, but I'm not sure.

If not, you could try removing and replacing that object, creating the "unlock" verb manually before you set it to be a container. (I know that sometimes when a verb conflicts with something else, you can avoid problems by creating the virb first).

Or you could set an initialisation script (which is useful to get around a lot of the web editor's limitations). On the features tab you would tick the box for an initialisation script; which adds an extra tab. Then on that tab you add the script:

this.unlock => {
  // insert your unlock script here
}

That would cause the unlock verb to be created (or overwritten if it already exists) whenever a new game is started. If the editor's restrictions prevent you from doing something, quite often it is still possible to use the initialisation script to create it once the game is running.


Just out of curiosity, how would you edit unlock if it wasn't a verb, but just part of a script?


Oh wow, thank you again! I think I saw exactly what my problem was - I was able to use the web editor to create my custom UNLOCK command, but I had to do it before marking the container as lockable, just like you said.

And thank you for the advice about the initialisation script! I'm sure that will prove quite useful as I learn more about what I can do!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums