Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[API Bug] End of turn script doesn't trigger turn order change...

Using !eot in this script... if (msg.type == "api" && msg.content.indexOf("!eot") !== -1) { var c = Campaign(); var pre_turnorder = c.get('turnorder'); if (!pre_turnorder) { return; } var turn_order = JSON.parse(c.get('turnorder')); if (!turn_order.length) { return; }; var turn = turn_order.shift(); turn_order.push({ id: turn.id, pr: turn.pr, custom: "Turn Counter" }); Campaign().set("turnorder", JSON.stringify(turn_order)); } ... doesn't trigger ... on("change:campaign:turnorder", function(obj, prev) { ... which is necessary for the highlight and round tracker scripts I use. I could probably copy and adjust what I have in the other scripts into the !eot scripts, but that would just be creating redundant code I would have to keep updated in two places.
This has come up on the forums before, but I noticed it wasn't in the Wiki so I just documented it: <a href="https://wiki.roll20.net/API:Events" rel="nofollow">https://wiki.roll20.net/API:Events</a> 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. If changes made to objects in the API scripts triggered change events, there would be no way to prevent an infinite loop from forming in many cases. The easiest way to handle this is just to put your own "hooks" into place. For example, you can put the the "change:campaign:turnorder" functionality into a function called "handleTurnOrder()". Then you call that function both when the change:campaign:turnorder event is triggered for remote changes, and when your other script modifies the turn order.
Ah, makes sense. Lot of work to re-write my scripts though. Bleh.