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

[Question] Can you use setAttrs() with the callback function of another setAttrs()?

1527479732

Edited 1527479762
Darren
Pro
Sheet Author
API Scripter
Sample code setAttrs({ field1: 0, field2: 0, field3: 0 }, function() { setAttrs({ field4: 123 }); }); I'm trying this and field4 isn't getting populated.  It is literally so straightforward, that my only idea is that you can't nest them. And yes, I'm aware that in the very simple example above, I could just add field4 to the first setAttrs().  But then that wouldn't answer the question of, can you nest them?
1527483382
Jakob
Sheet Author
API Scripter
Yes, you can. The problem in your example is that callback is the third  argument of setAttrs.
1527492499
Darren
Pro
Sheet Author
API Scripter
Jakob said: The problem in your example is that callback is the third  argument of setAttrs. Well, now I'm confused.  The docs ( Roll20 SheetWorker Docs ) says that the 2nd and 3rd arguments are optional and I'm not using the 2nd argument on any of my other setAttrs().  And the docs say the only valid value for the 2nd argument is "silent".  None of the examples use it.  How would you fix the sample code I had?
1527493345

Edited 1527493502
Jakob
Sheet Author
API Scripter
Sure, the second argument is optional, but you still have to provide it if you want to supply a callback. You could write it like this: setAttrs({ field1: 0, field2: 0, field3: 0 }, null, function() { setAttrs({ field4: 123 }); });