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

Roll20 turnorder (initiative) sync when changing maps

1764677119

Edited 1764680103
I have discovered that Roll20 does not automatically synchronize the pageid for each token in the turnorder, and that's why the turnorder looks f'ed when changing maps.  on('chat:message', function (msg) {     if (msg.type !== "api") return;     if (msg.content === "!syncinit") {         let turnorder = JSON.parse(Campaign().get("turnorder"));         let ppid = Campaign().get("playerpageid");         turnorder.forEach(e => {             e._pageid = ppid         });         Campaign().set("turnorder", JSON.stringify(turnorder));        } }); This is the minimum amount of code I've found to correctly synchronize across maps. It is literally getting the current player page id ( which is the ID of the map that has the orange bookmark thing on AKA the currently viewed map ) and sets the page id of all tokens to that page id. Nothing else needs changing, because it is just copying the current turnorder and making just that one modification. I am not sure why there is a pageid for each token. You could have a different initiative order displayed for each token in the turnorder, I guess ( which I have never seen the need for). This could just be a button on the initiative or somewhere saying "sync initiative with this page" or something. The current code lets anyone use the command, not just the GM ( which is a non issue really ). EDIT: on('change:campaign:playerpageid', function () {         let turnorder = JSON.parse(Campaign().get("turnorder"));         let ppid = Campaign().get("playerpageid");         turnorder.forEach(e => {             e._pageid = ppid         });         Campaign().set("turnorder", JSON.stringify(turnorder)); }); You don't even need to run the command ( I just assumed that change:campaign:playerpageid  would work, there is no documentation on this that I can find). When you change the maps (the bookmark) it automatically updates the initiatives ( although it seems to work a little "funky" sometimes ). EDIT2: The adventure continues "Funky" from above meant that the currentpageid that it got from the trigger was the pageid BEFORE switching maps, so I've set a delay on('change:campaign:playerpageid', function(obj,prev) {     setTimeout(() => {         let ppid = Campaign().get("playerpageid");         let turnorder = JSON.parse(Campaign().get("turnorder") || "[]");         turnorder.forEach(e => {             e._pageid = ppid;         });         Campaign().set("turnorder", JSON.stringify(turnorder));     }, 200); }); For inexplicable reasons, the GM does NOT see the initiatives when switching maps if you do this, but players do, instantly. If I switch from GM to player, voila, I can see the initiatives, lol, but if I am a GM it doesn't work. The turnorder object from Campaign will give you the ids for the tokens from my understanding, so I can't really tie to why would it not work for the GM to see the initiatives on different maps ( you can only see it on the map you first rolled ) but switching from GM to player makes it work, very strange behaviour, but expected, given how poorly documented and designed the API is.
1764695198
Gold
Forum Champion
So are you thinking that this can be offered to GM's as an API Mod script, to install and run? Or are you thinking of this as a Roll20 Feature suggestion? (In that case, Copy your comments to the Suggestions & Ideas forum so that others can upvote it +1)
1764735551

Edited 1764735702
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Rylik! I'm not sure I understand the use case here. The turn order is supposed to show all tokens that currently track initiative, regardless of page, for the GM. Useful for splitting party scenarios or for prepping an encounter. Players only see token initiatives on the page they are viewing. Can you elaborate a bit more on what problem this behavior causes in play, and what the experience is like after running your script? It seems like rewriting the JSON for the turnorder to hack in token IDs for tokens not on that page would cause all sorts of confusion for other scripts that manage or reference the turnorder. Hmm. I think that a utility that removes all tokens from the turn order that are not on the current page would be more useful in my case. It would clear up cases of double initiative when the GM asks for initiative before clearing a previous turnorder.