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

Is there a way for sheetworker to access global variables (state or something else)?

Some of my API scripts set global variables that have an effect on my character sheet (e.g. the current date, the current location of the scene, etc.), but I'm unaware of any method to communicate this information to the sheetworker aside from setting a corresponding attribute on the character sheets themselves.  With 50+ NPCs and constantly growing, I'm concerned about the efficiency of calling setAttrs() fifty times every time the date changes.  Is there some way for the sheetworker to access data that has been set by the API as they need it?
1564545484

Edited 1564545537
GiGs
Pro
Sheet Author
API Scripter
AFAIK, attributes are the only way to do this. APIs have access to lots of things, but character sheet workers only have access to the character sheet's attributes.  If you write an API to change an attribute on all 50 sheets at once, then there might be a momentary lag as the those changes occur, and any events those changes trigger are fired, cascading till all events are complete. But once this is done, its over, and the sheet workers lie dormant. And this sis something you usually do on demand, as needed - not something which is happening , say, every few minutes of gameplay. So there's not really a problem. The existence  of lots of attributes on lots of sheets can cause campaign lag in extreme situations (hundreds of sheets with hundreds or more attributes each, like when people try to create the entire monster manual in their campaign), but the sheet workers themselves are a minuscule part of that. Is there are reason you are changing a date attribute on all 50 sheets at once? I'm wondering what use-case is making you worry about this?
1564547649
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
My question would be why are you storing the current date, scene location, etc in every character? Do your sheetworkers actually need that data to do something on the sheet? Generic campaign info like this seems more appropriate to store in a handout or a generic "campaign status" character that you can call the requisite attributes from in macros.
Use Case:  I've recently added a system of "roll effects" that attach to characters and impact the rolls they make using a sheetworker-based dice roller.  These roll effects can be location-dependent (i.e. I set each scene in a city "District"; Districts have various effects, some of which apply to rolls, and can depend on the character making the roll, e.g. "vampires of Clan Brujah get +2 to Intimidate rolls in this District").  Other effects are time-dependent, relating to resources that refresh each week, effects with durations, effects that apply only at night, etc. etc.  There is also a Projects system by which long-term goals are represented by a Project Die that starts at 10, decreases by one every Project Increment (a period of time), and completes when the Project Die hits 0.   I've considered other ways to do it, including offloading all of this to the API and controlling everything with API-based scripts.  But the wide variety of attributes, systems and otherwise-unrelated mechanics that are affected by time/location would make this a prohibitively-intensive refactor, whereas the sheetworker is already set up to handle everything---it just lacks a way to know the location/time without mass-setting an attribute as described. I'll keep thinking on this.  I've already got a few possible solutions, including a way to toggle NPCs as "active" or "inactive" such that only the "active" NPCs get the frequent location/time updates... not sure if I'll be able to set a sufficient number of them "inactive" to make a dent, but we'll see!