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

Use sheetworkers to randomly generate attribute values?

1522820260

Edited 1522820312
vÍnce
Pro
Sheet Author
Is it possible to use sheetworkers to randomly generate a value and apply it to an attribute?  Basically, make a dice roll within the sheet and set an attribute's value with the result.  Use case; enabling a buff that adds 1d8+@{level} temporary hit points. ie  Aid (pathfinder spell)  I could see this being used to randomly generate starting abilities, monster/npc hp, etc.  Possible? Thanks
1522820879
GiGs
Pro
Sheet Author
API Scripter
Yes, this is possible. You could have an input, say a checkbox (which if you like, could be styled to look like a button). When you click this checkbox, the change event fires, and the a sheetworker rolls the stat and applies it as you need. You might want to have the sheetworker only fire when the sheetworker is checked (so unchecking it doesnt trigger the roll), and have the sheetworker uncheck the checkbox. So, you click it, it rolls stats, and sets the checkbox back to unchecked, ready to be clicked again. Visually this looks better than having the roll happen whenever you check or uncheck the sheetworker, or having to uncheck it manually before you can check it again.
1522823154
vÍnce
Pro
Sheet Author
G G said: Yes, this is possible. You could have an input, say a checkbox (which if you like, could be styled to look like a button). When you click this checkbox, the change event fires, and the a sheetworker rolls the stat and applies it as you need. You might want to have the sheetworker only fire when the sheetworker is checked (so unchecking it doesnt trigger the roll), and have the sheetworker uncheck the checkbox. So, you click it, it rolls stats, and sets the checkbox back to unchecked, ready to be clicked again. Visually this looks better than having the roll happen whenever you check or uncheck the sheetworker, or having to uncheck it manually before you can check it again. Sweet.  I believe the recalc button on the PF sheet works off of this method.  For my immediate application (apply temp hp from a buff); enabling a given buff would trigger a hidden checkbox(temphp-toggle) that in turn triggers the event to roll the temp hp, add it to HP-temp and HP-temp|max, and then reset temphp-toggle. Easy as mud.
1522823579
Jakob
Sheet Author
API Scripter
For my immediate application (apply temp hp from a buff); enabling a given buff would trigger a hidden checkbox(temphp-toggle) that in turn triggers the event to roll the temp hp, add it to HP-temp and HP-temp|max, and then reset temphp-toggle. Easy as mud. Seems there is no need for the hidden checkbox in this picture?
1522823896

Edited 1522824009
GiGs
Pro
Sheet Author
API Scripter
You dont need to use a checkbox to trigger it. Any change event can do it. I just used that as an example. If you're enabling a buff (however you do it), that can be the trigger to roll the buff. i like using the method I described, because you have to be careful not to repeat the trigger. It's easy to create events that fire when you dont expect them to.
1522824182
vÍnce
Pro
Sheet Author
I suppose not since the sheetworker event could be written to only trigger once when the buff was enabled "on", and then run the temphp function.  js is not my forte... but I'm intrigued by it. ;-)
1522967608
AquaAlex
Sheet Author
Translator
API Scripter
Vince said: I suppose not since the sheetworker event could be written to only trigger once when the buff was enabled "on", and then run the temphp function.  js is not my forte... but I'm intrigued by it. ;-) DO IT! :) And share for everyone else that would like to use it :)
1522974012
chris b.
Pro
Sheet Author
API Scripter
You can but I don't know of a way to use Roll20's good random number generator without using an API script instead. the sheetworker would only have access to javascript's random commands which leave much to be desired. That is why we never put random anything in the sheet. But it might be something for the api companion
1522974668
GiGs
Pro
Sheet Author
API Scripter
Doesn't the roll20-created randomInteger function work in sheet workers? I thought I'd used it but I may be misremembering.
1522979516
chris b.
Pro
Sheet Author
API Scripter
i don't think so... maybe someone can confirm
1522981168
GiGs
Pro
Sheet Author
API Scripter
Looks like you're right, I just tested it and it's not recognised. Still Math.random works. For the purpose of rolling a few stats and similar things, it should be fine.