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

[BUG] setting playerspecificpages

1463522148

Edited 1463522209
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
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
1463557522

Edited 1463557626
Lithl
Pro
Sheet Author
API Scripter
That does sound like a bug. Although now I'm hung up on your weird use of _.each. You could just do this: _.each(playerid, function(id) { pp[id] = destinationid; }); =P Or, if you're dead-set on indexing into the playerid array: _.each(playerid, function(id, k) { pp[playerid[k]] = destinationid; }); // this also works: _.each(playerid, function(id, k, collection) { pp[collection[k]] = destinationid; });
1463574410
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Lol, well, that is probably me just being a noob coder :)