
While working on my Page Navigator script, I came across what I think might be a bug either in the API or how roll20 is handling the 'playerspecificpages' property of campaigns. If the property is empty (aka. set to its default value of false), then Campaign().set({playerspecificpages: new playerid:pageid pair}) works fine. But if the property already has a value in it, and you simply want to update it by doing something like this: movePlayer = function(destinationid, playerid){ let pp = Campaign().get('playerspecificpages');
log(pp);
log(Campaign().get('playerspecificpages')); pp = (_.isObject(pp) ? pp : {} ); var iteration = 0; _.each(playerid, function(){ pp[playerid[iteration]] = destinationid; iteration++;
}); Campaign().set({playerspecificpages: pp});
log(Campaign().get('playerspecificpages'));
}, The currently split players are left at their pages (which is good and desired), but whichever player you are trying to move to split from the party also is unaffected, leaving them at whatever page they were on and in the player ribbon if they were already there. The weird bit is that the log calls will show that Campaign.get('playerspecificpages') does update correctly, the change just isn't propagated to the game itself. To get this to work I discovered this workaround: movePlayer = function(destinationid, playerid){
let pp = Campaign().get('playerspecificpages');
log(pp);
log(Campaign().get('playerspecificpages'));
pp = (_.isObject(pp) ? pp : {} );
var iteration = 0;
_.each(playerid, function(){
pp[playerid[iteration]] = destinationid;
iteration++;
});
Campaign().set({playerspecificpages: false});
Campaign().set({playerspecificpages: pp});
log(Campaign().get('playerspecificpages'));
}, According to the logs, the two functions will look identical, but this one will correctly split off the new players from the party and won't incorrectly move any currently split players. The two Campaign().set's do not "stutter change" the players to both the player ribbon and their split from the party page, which is what I more than half expected when I tried this out of frustration. Any ideas on why setting the 'playerspecificpages' property is so weird? Thanks, Scott