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

[custom sheet] limitations of auto-updating values and sheet script values

1537275943

Edited 1537276114
Hello everyone :) I created this new post as a continuation to an older, already closed, post .  As a quick summary of the topic at hand: auto-calculated values in character sheets will not appear under the attributes in a character sheet (in the tab "attributes and abilities"). a few example consequences: 1) they cannot be used for setting token bars; 2) they cannot update already existing attributes that are found under the attributes list. The main problem is that this creates two separate groups, one of auto calculated fields and their respective limited attributes; the other is the group of attributes handled by sheet scripts. The interaction abilities are quite limited, and worse of all one-way only. I might use attributes update by scripts and take them to the autocalc fields - but not the other way around.  EDIT: and this can be a big problem when you consider that autocalc values are updated by API created events. the sheet scripts cannot use this as a trigger. I wanted to know the following: am I understanding these limitations correctly? Or is there any way to implement a more continuos behaviour between autoupdate values and sheet script handled values? Hope this post is understandable to some, I know I went full technical and I feel like describing these topics is tricky.
1537277895
Jakob
Sheet Author
API Scripter
Yeah, you've got it just about right. That having been said, there's no reason to ever use auto-calculating fields for anything, they're only provided for legacy reasons at this point. Everything that can be done with auto-calc fields can be done by sheet workers, and probably in a more performant way. I have written quite a bit of sheet code, and I have never used auto-calc fields anywhere.
1537283069
Finderski
Pro
Sheet Author
Compendium Curator
gui8312 said: EDIT: and this can be a big problem when you consider that autocalc values are updated by API created events. the sheet scripts cannot use this as a trigger. I believe this is incorrect, but I could be wrong.
1537286546
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Finderski said: gui8312 said: EDIT: and this can be a big problem when you consider that autocalc values are updated by API created events. the sheet scripts cannot use this as a trigger. I believe this is incorrect, but I could be wrong. I think what he means is that an API script could update an attribute that affects an autocalc attribute. In this case the sheet workers would have to watch for changes to all the attributes that affect the autocalc values instead of just watching the autocalc value. This is certainly true, and is just one more reason to follow Jakob's advice to never use autocalc fields.
1537337266

Edited 1537337422
Thanks for your answers! One follow up: I want an API script to change some attribute. If I look for a change:attr event with the sheet scripts should it fire? I believe it would not, that was my impression. Believe me if I could use sheet worker scripts only that would be great news. But I want this kind of updating sequence.
1537338478
GiGs
Pro
Sheet Author
API Scripter
The basic set function won't, but there's a SetWithWorker function you can use, which will cause change events to fire.
1537338574
Jakob
Sheet Author
API Scripter
It does fire if you use attr.setWithWorker() instead of attr.set().
That is amazing! Thank you :D
1537367266

Edited 1537367682
Can I get some pointers about how to use this function? Just a quick example would be great... or did I get it right? I would use this in my API script and any changes produced this way would make the workers fire. Any worker that looks for that attr changing. In the documentation, 'cleric' is the value the attr is set to.
1537367758

Edited 1537368014
GiGs
Pro
Sheet Author
API Scripter
Yes, you use it exactly the same as obj.Set, and any workers will detect it automatically. You dont have to do anything beyond changing set to setWithWorker to use it. Like most wiki entries, the example is pretty unhelpful. It says: getObj ( "attribute" , "-KUI1fO2L7Jv0Y4AOSFK" ). setWithWorker ({ current: "Cleric" }); Imagine that the attribute  -KUI1fO2L7Jv0Y4AOSFK  is pointing to an input named Class, on the character named Example. When this snippet is run, that attribute gets its value updated to "Cleric", and any sheet workers watching the Class attribute would be triggered on that character.
Yeah the example I had was a bit too confusing... so thanks for the confirmation! Really appreciate all the help guys :)