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

Campaign() property for the Page ID that the GM is looking at?

There doesn't seem to be any such thing listed for the Campaign() object.  I'm trying to bulletproof an initiative script to prevent it from running on a page the players aren't on (since turn order is based on Token IDs which are specific to a Page).  The API documentation suggests that the 'initiativepage' property would show a page ID if the turn order were active on a different page, but the turn order doesn't behave that way nor does 'initiativepage' seem to have any values other than 'true' or 'false'.
1618795367
The Aaron
Roll20 Production Team
API Scripter
I have some helper functions you might like: // eslint-disable no-unused-vars const getActivePages = () => [...new Set([ Campaign().get('playerpageid'), ...Object.values(Campaign().get('playerspecificpages')), ...findObjs({ type: 'player', online: true }) .filter((p)=>playerIsGM(p.id)) .map((p)=>p.get('lastpage')) ]) ]; const getPageForPlayer = (playerid) => { let player = getObj('player',playerid); if(playerIsGM(playerid)){ return player.get('lastpage') || Campaign().get('playerpageid'); } let psp = Campaign().get('playerspecificpages'); if(psp[playerid]){ return psp[playerid]; } return Campaign().get('playerpageid'); }; const getPlayersOnPage = (pageid) => { let pages = {}; let ribbonPage = Campaign().get('playerpageid'); let psp = Campaign().get('playerspecificpages'); findObjs({type:'player'}) .forEach(p=>{ if(playerIsGM(p.id)){ const lp = p.get('lastpage') || Campaign().get('playerpageid'); pages[lp]=pages[lp]||[]; pages[lp].push(p.id); } else if(psp.hasOwnProperty(p.id)){ pages[psp[p.id]]=pages[psp[p.id]]||[]; pages[psp[p.id]].push(p.id); } else { pages[ribbonPage]=pages[ribbonPage]||[]; pages[ribbonPage].push(p.id); } }); if(pageid){ return pages[pageid]||[]; } return pages; }; const getGMPlayers = (pageid) => findObjs({type:'player'}) .filter((p)=>playerIsGM(p.id)) .filter((p)=>undefined === pageid || p.get('lastpage') === pageid) .map(p=>p.id) ; The GM's page is actually on the player object for them.  It's a bit strange, but it make some sense based on how GMs are handled, and where the data is being collected. I agree with you about the initiativepage property having changed at some point.  In practice, it kind of doesn't matter as you can have multiple pages's tokens in the turn order simultaneously, so the page id for the turn order is really the subset of pages for all the tokens in the turn order.
I was just trying to be thorough.  I remember my usual DM having problems with duplicate entries in the turn order resulting from having tokens with non-unique names (typically players, but occasionally boss-types) appearing on multiple pages.  Thinking about this further, however, I'm remembering that I specifically excluded PC tokens from my initiative roller script so that they could be incidentally captured in a selection area and remain unaffected.  Thanks very much for the additional info, and in restrospect it actually makes perfect sense that GM is a special case of Player.  I'll think some more about whether I still need the check now, but I may yet in the future.