
So I was throwing together a script for a personal game and found that setting a handout's notes property with the API was also triggering the change:handout:notes event. It caused an infinite loop there, since my script was listening for that even and updating a handout when it occurred. I can work around this for my needs, but this page in the wiki leads me to believe that this is a bug: Note: Events are only triggered by changes made by players/the GM playing the game. Events will not be triggered by API changes. So if a player moves a piece on the tabletop, you would receive a "change:graphic" event. If you modify the same graphic's property in an API script, there will not be a "change:graphic" event triggered. Code to reproduce: (gist) var eventDemo = eventDemo || (function () {
let registered = false;
const registerEventHandlers = function () {
if (registered) return;
// When any page is updated, we will log the event and change the notes property
on("change:page", (page) => {
log("change:page");
updateHandoutNotes("Event Demo", "Last updated page: " + page.get("name"));
});
// When any handout's notes are updated, we will log the event
on("change:handout:notes", () => {
log("change:handout:notes");
});
registered = true;
};
const createOrGetHandout = function(name) {
let search = findObjs({_type: "handout", name: name});
return (search && search.length > 0 && search[0]) || createHandout(name);
};
const createHandout = function(name) {
return createObj("handout", {
name: name
});
};
const updateHandoutNotes = function(handoutName, newNotes) {
let handout = createOrGetHandout(handoutName);
handout.set("notes", newNotes);
};
return {
init: registerEventHandlers
}
}());
on("ready", function () {
eventDemo.registerEventHandlers();
}); The demo I hacked together to reproduce the issue updates a handout every time a Page is changed, and puts a log in the console on both the change:page and change:handout:notes events. As you can see, when I change a page's name, it triggers the change:page event which uses the API to update the handout, triggering the change:handout:notes event.