Noob to JS - Locks & Unlocking

Hey All - Sorry if this is really stupid question, or it's the wrong place...

I've just started working through the tutorial for QuestJS. Quite the challenge for me but thought it would be fun to give it a go over the holidays. All was fine up until the lockable objects bit.

Am I right in thinking that with the code, I should be able to unlock the glass cabinet?

createItem("glass_cabinet", CONTAINER(true), LOCKED_WITH("cabinet_key"), {
	loc:"lounge",
	transparent:true,
	examine:"A cabinet with a glass front",
	
});
createItem("cabinet_key", KEY(), { 
  loc:"garage",
  examine: "A small brass key."
});

I fear I may have missed something as I keep getting the error ReferenceError: no_key is not defined.

Does anyone know if there is there something else I need to set up?


Hello.

That's all you need.

If the player is holding the KEY (in this case the "cabinet_key" item), the glass cabinet can be opened. (It will say you unlocked it first.)


This is a blank game with your code snippet added (although I changed the location of the key to the lounge):


image


I fear I may have missed something as I keep getting the error ReferenceError: no_key is not defined.

Whoops! I didn't see that the first time I read your post.

It sounds like you need to add this to your code (but it was in my version of QuestJS (v0.3) already):

lang.no_key = "{nv:char:do:true} have the right key.";

To check, hit <F12> to open your dev console, then just enter: lang.no_key. If it returns 'undefined', you need to add the line of code above to your game.

Here's what it looks like in by browser:

image


Thanks Richard - Makes sense.

I'll try re-downloading the zip files and starting from scratch. Clearly something has gone astray somewhere. I always get no_key not defined error when trying to unlock an object/door.


Ah! that's interesting, I can open the cabinet when carrying the key if I use "open cabinet".

If I use "unlock cabinet" instead then I get the error message.


O-ho!

You found a bug!

If you open your "lib/_templates.js" file, go down to line 643 (or somewhere around there, depending on your version), you will find this:

    unlock:function(isMultiple, char) {
      const tpParams = {char:char, container:this}
      if (!this.locked) {
        msg(lang.already, tpParams);
        return false;
      }
      if (!this.testKeys(char, false)) {
        msg(no_key, tpParams);
        return false;
      }
      msg(unlock_successful, tpParams);
      this.locked = false;
      return true;
    },

One line in there is the culprit: msg(no_key, tpParams);

That should be msg(no_key, tpParams);, and I should have noticed your error just said "no_key" rather than "lang.no_key". (Doh!)


The whole unlock bit should be this:

    unlock:function(isMultiple, char) {
      const tpParams = {char:char, container:this}
      if (!this.locked) {
        msg(lang.already, tpParams);
        return false;
      }
      if (!this.testKeys(char, false)) {
        msg(lang.no_key, tpParams);
        return false;
      }
      msg(unlock_successful, tpParams);
      this.locked = false;
      return true;
    },

Normally, I would advise redefining the function in your own code, but this is set as a const, which means it will just throw an error if you try to modify it. Therefore, I believe editing the actual file is the only solution.


A-ha!!! I See!!! Phew - for a while I thought I was going crazy. LOL


PS

That bug has already been fixed in the file which is currently on GitHub, but it is not updated in the version 0.3 zip on there.

I assume all updates will be in the upcoming version 0.4 zip file.


for a while I thought I was going crazy

Heck; I think that all the time! (That I'm going crazy, not that you're going crazy.)


I found a bunch of missing language bits recently that are on GitHub, but not in the zip file yet. Give it 24 hours I will put out version 0.4 with the updates.


No problem - Loving that doors can be in two rooms at once. This is a whole new world! :)


Loving that doors can be in two rooms at once. This is a whole new world!

I second that emotion!


Version 0.4 is now available.


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

Support

Forums