ThePix / QuestJS

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

Issues with dynamic talk to (dropdown list of topics) #51

Closed Kln95130 closed 3 years ago

Kln95130 commented 3 years ago

Hello. I encounter the following issues with the current version (0.4) of the framework, regarding "talk to" with topics.

I am trying to test the following code:

createItem("Mark", NPC(false), {
  loc: "lounge",
  properName: true,
});

createItem("Mark_How", TOPIC(true), {
  loc:"Mark",
  alias: "How are you doing?",
  hideAfter: false,
  script:function() {
    msg("Fine, thank you.")
  }
});

createItem("Mark_Weather", TOPIC(true), {
  loc:"Mark",
  alias: "Nice weather today.",
  hideAfter: false,
  script:function() {
    msg("Quite.")
  }
})
  1. When opening the dropdown menu, I have an "Examine" that is pasted after the topic alias. capture

  2. The topic responses are displaced. When clicking on "How are you?", nothing happens. When I select "Nice Weather today", I get the "Fine, thank you." answer. If I select "Nevermind", I get the "Quite." answer, and so on.

These issues are specific to the dropdown, so I think it's something related to how it is built by the library. I will investigate a little further. If I find something, I will update this ticket.

Kln95130 commented 3 years ago

Update: On a hunch, I modified the io.showdropdown function as such, and issue number 2 is fixed. Not sure exactly why, but the fix is basically going along with the behavior of the dropdown menu. The changed part is to use "i +1" in the value of the option elements instead of "i": s += '<option value="' + (i + 1) + '">';

function showDropDown(title, options, fn) {
  const opts = {article:DEFINITE, capital:true}
  io.input(title, options, false, fn, function(options) {
    let s = '<select id="menu-select" class="custom-select" style="width:400px;" ';
    s += 'onchange=\"io.menuResponse($(\'#menu-select\').find(\':selected\').val())\">';
    s += '<option value="-1">-- Select one --</option>';
    for (let i = 0; i < options.length; i++) {
      s += '<option value="' + (i + 1) + '">';
      s += (typeof options[i] === 'string' ? options[i] : lang.getName(options[i], opts))
      s += '</option>';
    }
    msg(s + "</select>");
    //$('#menu-select').selectmenu();
    $('#menu-select').focus();
  })
}

I'll keep looking for the "Examine" out of nowhere

Kln95130 commented 3 years ago

Issue 1's cause found: the "Examine" is added by the item-links library.

I solved the issue by adding an "onCreation" function to TOPIC, which removes the "examine" verb from the verblist (which caused the issue)

const TOPIC = function(fromStart) {
...
    onCreation: function(o) {
      o.verbFunctions.push(function(o, verbList) {
        verbList.shift()
      });  
    },
ThePix commented 3 years ago

Thanks for that. I have uploaded to GitHub a new version (but not a release version yet). Issue 2, you were spot on. Issue 1 was that the link library was adding "Examine" as a clickable verb; I added and option in the library to stop that, and showDropDown and showMenu use that.