ThePix / QuestJS

A major re-write of Quest that is written in JavaScript and will run in the browser.
MIT License
66 stars 13 forks source link

Double option with container #28

Closed DakinQuelia closed 3 years ago

DakinQuelia commented 3 years ago

Hello,

I've a little problem with my code :

createItem("dantooine_enclave_chambre_coffre", CONTAINER(true), {
  alias: "coffre personnel",
  scenery: false,
  loc: "dantoine_enclave_chambre",
  closed: true,
  defArticle: "un",
  indefArticle: "un",
  examine: "Un coffre en duracier contenant des objets personnels.",
  openMsg: function() 
  {
    if (!this.getContents(world.LOOK).length > 0)
    {
      msg("Vous ouvrez le coffre personnel. A l'intérieur, vous ne trouvez rien.");
    }
    else 
    {
      msg("Vous ouvrez le coffre personnel. A l'intérieur, vous trouvez : " + formatList(this.getContents(world.LOOK), {lastJoiner:lang.list_and, article:INDEFINITE}) + ".");
    }
  },
  closeMsg: function()
  {
    msg("Vous fermez le coffre personnel.");
  },
});

It displays TWO same options : https://i.goopics.net/ka8VG.png

Thanks per advance.

KVonGit commented 3 years ago

Hello.

It's not your code. It appears to be a bug in Quest. I checked an openable item in my own game, and it did the same thing.

When I add this code to my settings.setup function, it seems to fix the problem.

        OPENABLE_DICTIONARY.close = function(isMultiple, char) {
            const tpParams = {char:char, container:this}
            if (!this.openable) {
              msg(prefix(this, isMultiple) + lang.cannot_close, tpParams);
              return false;
            }
            else if (this.closed) {
              msg(prefix(this, isMultiple) + lang.already, {item:this});
              return false;
            }
            //this.hereVerbs = ['Examine', 'Open']; //KV commented out to fix bug.
            this.closed = true;
            this.closeMsg(isMultiple, tpParams);
            if (this.onClose) this.onClose(char)
            return true;
           };
        //-----------------------------------------------------------
        //END OF FIX OPENABLE adding duplicate verbs onto pane items|
        //-----------------------------------------------------------

If you don't already have a settings.setup function in your code, open the file 'game/settings.js', and add this code:

settings.setup = function(){
        OPENABLE_DICTIONARY.close = function(isMultiple, char) {
            const tpParams = {char:char, container:this}
            if (!this.openable) {
              msg(prefix(this, isMultiple) + lang.cannot_close, tpParams);
              return false;
            }
            else if (this.closed) {
              msg(prefix(this, isMultiple) + lang.already, {item:this});
              return false;
            }
            //this.hereVerbs = ['Examine', 'Open']; //KV commented out to fix bug.
            this.closed = true;
            this.closeMsg(isMultiple, tpParams);
            if (this.onClose) this.onClose(char)
            return true;
           };
        //-----------------------------------------------------------
        //END OF FIX OPENABLE adding duplicate verbs onto pane items|
        //-----------------------------------------------------------

}
DakinQuelia commented 3 years ago

Thank you very much. It's fixed.

A pull request maybe ?

KVonGit commented 3 years ago

A pull request maybe ?

ThePix will see this and either add my fix or add a better fix (usually the latter, ha-ha).

Also, I think my Linux line-breaks mess up the existing files, which have Windows line-breaks.

Either way, ThePix usually has a better fix. (Hey! That rhymed!)

Have a good night! Or day, depending on where you are in the world!

ThePix commented 3 years ago

Fixed. Thanks Dakin for spotting and KV for the fix (that was the best solution)