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

API and sheet workers

1451381674
Natha
KS Backer
Sheet Author
API Scripter
It might have been answered elsewhere, if so, sorry to ask: is there any interaction between API scripts and sheet workers? For example, if an API script adds ( with createObj("attribute"...) ) or  modifies (with obj.set() ) an attribute , will this fire a sheet worker set on the "on("change:...")" of the same attribute ? Can the getAttrs() and setAttrs() functions, described in the sheet workers wiki, can be used in an API script ?
1451401733
The Aaron
Pro
API Scripter
Based on other conversations, I'll summarize (I've not completely tested all of this, YMMV): 0) sheet workers run in the user's browser, API scripts run on the API server.  1) changes to attributes by sheet workers cause events for on('change:attribute',...) in the API [unverified but Riley said so!] sheet worker changes look like the player made the change.  2) changes to attributes by the API DO NOT trigger change events in the sheet workers.  Given the above, you could have communication in one direction by having a hidden attribute that the sheet workers change and an API script monitoring that attribute.  You could similarly have a "work queue" for a sheet worker by doing the same thing in reverse, but you would need to check the queue when other events happened as the API wouldn't be able to trigger directly.  Let me know if that doesn't make sense and I'll try to explain it better. :)
1451402908

Edited 1451406725
Natha
KS Backer
Sheet Author
API Scripter
Thanks Aaron (once again :) ). It makes sense. In facts, I'm writing an API character creation script which sets value for a bunch of attributes, so I didn't want that it fires unwanted sheet workers event. So, the current monodirectional behaviour suits me fine. Quick question: is it possible to add a row* to a repeating fieldset with the API? (I searched a bit but didn't find anything usefull). *: if it's of any help, it would be the first row(s) of a repeating fieldset, as I want to do this in the aforementioned character creation script.
1451406724
The Aaron
Pro
API Scripter
The API doesn't have access to doing that.  However, you could have a hidden field on your character sheet that the API sets with information (a "work queue" if you will... =D ) and check it using the 'sheet:opened' event in a sheet worker. Then just use that information to create the new row.  I should write that into my TheAaronSheet...
1451406816
Natha
KS Backer
Sheet Author
API Scripter
Good idea, thanks
1451406887
The Aaron
Pro
API Scripter
No problem!!  =D
1456074870

Edited 1456074882
I really wished it would be possible from the API, it would make a lot of stuff easier. Repeating Sections are great, but they really need some last fixes (like nested repeating sections, creating rows from the API,...)