Quest 6: Change listeners

Hello.

I didn't know change listeners were added to QuestJS until I read about it in another thread today. (This is my fault for not keeping up with the docs.)

I have been using the vanilla JS method for change scripts, and it seems to work right -- even after loading a saved game.

Now, I'm wondering if it might break something in the game. . .


UPDATE

Yes. My code did break something.

Also, I prefer the new, built-in way.

Hurray for change scripts!


This is my fault for not keeping up with the docs.

They were not in the docs until yesterday, so not your fault

I have been using the vanilla JS method for change scripts

What is that?


Just setters and getters.

function setupAtt(o, att, val) {
  o['_' + att] = val
  Object.defineProperty(o, att, {
    get: function () { return this['_' + att]; },
    set: function (newValue) {
      this[att + 'Bak'] = this['_' + att]
      if (this[att + 'OnChange']) {
        this[att + 'OnChange'].call(this, newValue)
      }
      this['_' + att] = newValue
    }
  });
}

Also note that I later found out this bit of code isn't the code that was causing issues.

I found this out after I changed everything over to the new change script format. I had starting adding a new item to the game a couple of weeks ago, but I was interrupted halfway through writing the item's createItem() function and forgot to go back and finish.


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

Support

Forums