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

Script Worker help needed

1503862235
MSG
Pro
Sheet Author
I'm working on a character sheet and find I am in need of help regarding the Script Worker. In my sheet, the "Intuition" has a name="attr_Intuition" value="@Intuition".  Another field (that I added) is: name="attr_InitModifier" (using <select> for possible values) that is used for Initiative rolls.  What I would like to do is to get rid of the selection and have it auto-compute.  In JavaScript, this would be something like this: if (@Intuition <= 10) {    attr_InitModifier = 0; } else if (@Intuition > 10 && @Intuition <= 20) {    attr_InitModifier = 1; } else if (@Intuition >20 && @Intuition <= 30) {    attr_InitModifier = 2; } ... else {    attr_InitModifier = 6; } How would I go about making that work in the Script Worker?  I'm guessing the first line would be: <script type="text/worker"> on("change:intuition", function() {    // here's where I need code to do the above }); </script> Any help / guidance would be appreciated (or even a link to a real sample (aka - not the samples shown in the wiki - one using actual code)). Thanks!
1503863692

Edited 1503960994
Try this, I'm not actually sure if it will work but I've been reviewing the 5e OGL character sheet code and this seemed like it should work. on("change:intuition", function() { // Get the attributes you want to use for values. getAttrs(["intuition"], function(v) { var intuituion = parseInt(v["intuition"]); // Essentially the same as your if/else if/else block I thought var initModifier = Math.min(Math.floor(intutition/10), 6); // Set the attributes you want to change setAttrs({initModifier: initModifier}); }); }); Edit: Added the closing ); . Thanks Jakob! Edit 2: Changed the formula to account for the curveball
1503865421
MSG
Pro
Sheet Author
Thank you very much for that code.  Sadly, though, I must be doing something wrong, as I can't get it to work. Thank you for your time and assistance though.
1503867706
Kirsty
Pro
Sheet Author
Are you trying to update a disabled field? If you are, you'll need to set a hidden field and then set the disabled field to show the value of the hidden one. There's an example  on the wiki .
1503903190

Edited 1503903241
Jakob
Sheet Author
API Scripter
Kirsty said: Are you trying to update a disabled field? If you are, you'll need to set a hidden field and then set the disabled field to show the value of the hidden one. There's an example  on the wiki . Or just make the field readonly instead of disabled, that should work as well without the need for an extra field? Ah, and Kyle's code is missing a closing bracket + semicolon, otherwise it should work.
1503956558
MSG
Pro
Sheet Author
Thank you all for your responses! I will re-try the code, but I'm probably going to have to change it to the if / else to work, because they threw a curveball in at Modifier +5: Not sure why they did that, but those are the number ranges I need to test against. Thanks again, everyone, for your help!  Much appreciated!
Hey MSG, I changed the formula so that it will take the minimum of the value / 10 and 6. Didn't want a curveball like that to trip you up.
1503965332
MSG
Pro
Sheet Author
Thank you very much, Kyle G.!  I'll let you know how it goes when I've got time to test it (might be after I get back home on Sept. 2nd).