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

Doing something triviall

Spent the last 4+ hours trying to find documentation on the API - easier to find with Google than on the site :-( But, it didn't help.  I'm running code on that I want to affect the page that the GM is viewing.  I've spent HOURS and HOURS trying to get that minor piece of information out of the system.  I can get the page from the _lastpage of a Player Object.. Except that I don't have one.  Searching and searching, I was able to find findObjects ( {type='player'})  - but that doesn't return return any players that have the _lastpage set to anything other then undefined. Obviously, this should be Campaign().ViewedPage(), or maybe Campaign().LastGMViewedPage(), or well, SOMETHING... When I signed up for being able to use the API I didn't realize it was mostly undocumented, and a major hack-job :-(   At least, that is how it has come across to me. Makes me want to write my own site instead of fighting with this....
Code is taken from another script (that is worthless as it seems to always grab the page that the ribbon is on) // TODO: Make this return the ID of the page the GM is viewing module.getPageId = function () { var objs1 = findObjs({type: 'player'}); objs1 = objs1.filter( function(x) {if (typeof x === 'undefined') return false; return (typeof x._lastpage !== 'undefined');}) // Was throwing above with _lastpage not a property of 'undefined' so apparently, it returns undefined players when asked for them! // No documentation on the types of things (not listed on the findObjs method!  Seriously?) log('All Players:' + objs1); return objs1[0]._lastpage; // return new Player()._lastpage;   // One attempt. // return new Campaign().get('playerpageid');  // Original garbage };
1515928182
Jakob
Sheet Author
API Scripter
The documentation for the API is on the  Wiki .  The findObjs function should not be returning undefined objects, so I don't know what's going on there. I've never seen this happen. Make sure to only register the event handlers for your function on the "ready" event, maybe it's a problem that you are doing stuff before the API is ready? But this is conjecture so far... Anyway, in the documentation you can see that you cannot access most properties of Roll20 objects directly, but via a get() method, so it would be x.get('_lastpage') This will be either an empty string (if the player has never viewed anything as a GM) or a pageid.
the .get solved it.  I missed that part of the documentation (but figured it out before I read this.. :-( )  Thanks for the solution.