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

Running a script page by page

I am in the process learning the ins-and-outs of the how the API works. Am I correct that a given API script runs globally across all pages in a campaign rather than as a separate instance on an active page? If so, what would be the correct format for creating a process that performed a series of subprocesses as it iterated through each separate page in the campaign? Specifically I am working on a modified version of the Inventory Manager script (based on John C.'s original through Rouby's modifications). I am looking for an alternate to this line: var pageGraphics = findObjs({ _pageid: Campaign().get('playerpageid'), _type: 'graphic' }); which restricts the functionality of the script to the page with the Player Bookmark. Working off the model of the current script: var pageGraphics = findObjs({ _pageid: Campaign().get('playerpageid'), _type: 'graphic' }); _.each(pageGraphics, function (graphic) { I am experimenting with using the following to wrap the page-level functionality of the script, but have not been able to format/place it correctly to produce the results I want: var pageEach = findObjs({ _type: 'page' }); _.each(pageEach, function (page) { The original line tying the script to the Player Bookmark would then become (I think): var pageGraphics = findObjs({ _type: 'graphic' }); _.each(pageGraphics, function (graphic) { Let me know if seeing the totality of my current draft script would help. Thanks for any thoughts.
1437145352
The Aaron
Pro
API Scripter
A little baseline info: The pages are all just data to the API. All scripts for a given campaign are concatenation into a single (logical) file and executed in the context of the campaign. The scripts runs on an API server, separate from the shards running the campaigns. You are in the right track regarding performing operations on a single page's graphics, but I t's not clear to me what problem you're having from the above code. You might want to look at filterObjs() as it can be more versatile in producing a set of objects.
1437159150
Lithl
Pro
Sheet Author
API Scripter
If you wanted to operate on each page one at a time, you'd do something like this: var pages = findObjs({ type: 'page' }); _.each(pages, function(page) { var pageGraphics = findObjs({ pageid: page.id, type: 'graphic' }); _.each(pageGraphics, function(graphic) { // Do stuff with graphic }); }); With just the above code, all of the graphics in the campaign would be processed, but everything on one page would be processed before the graphics on the next page.