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 .
×

New sheetworker breaking all sheetworkers in custom character sheet

I've been editing the Astonishing Swordsmen and Sorcerers of Hyperborea character sheet to automate as much of it as possible to make character creation as fast as possible. The issue I'm running into is that one new sheet worker (a gender randomizer), upon being added into the rest of the scripts, seemingly breaks the rest of the sheetworkers.  Here is the troublesome sheet worker: on("clicked:genderroll", function() {     getAttrs(['gender'], function(values) {         var gender = parseInt(values.gender)||0;         var genderroll = Math.floor(Math.random() * 10) + 1;         if (genderroll <= 5 ) {             gendervalue= 0;         }         else if (genderroll >= 6) {             gendervalue= 1;         }         setAttrs({  "gender": gendervalue });     )}; )}; Here is it's code up top: <div class="sheet-ligne">      <span class="sheet-lib1 sheet-wid70">Gender</span>      <select name="attr_gender" style="width: 140px;">       <option value="0">Man</option>      <option value="1">Woman</option>      </select>      <button class="sheet-actiond100" type="action" name="act_genderroll"></button> </div> I have other sheetworkers that function similarly (random select from a drop down menu) that are working just fine so I'm not sure what it could be besides a syntax error that I keep missing. 
1658901592

Edited 1658904571
vÍnce
Pro
Sheet Author
Does it work if you strip out getAttrs?  Since you aren't actually using the value of 'gender' to do any calculations, I'm hypothesizing that it's not needed. (note: my roll20 sheetworker skills are novice at best, so I'm just thinking out loud with an ignorant mind, lol) edit/update: this seems to work for me. on('clicked:genderroll', function () { let gendervalue = ''; const genderrollValue = Math.floor(Math.random() * 10) + 1; if (genderrollValue <= 5) { gendervalue = 0; } else if (genderrollValue >= 6) { gendervalue = 1; } setAttrs({ gender: gendervalue, }); }); I made a few changes. Removed getAttrs.(unnecessary) Declared the variable 'gendervalue'.(should declare all variables) Changed the variable of 'genderroll' to 'genderrollValue'. (Given it was the same name as the action button I thought it could cause a conflict) In the setAttrs, I removed quotes from "gender". (I think no quotes is the proper syntax in this instance) And finally what was probably the real culprit for what was breaking your workers, the last line needed to be inverted from ')};' to '});' Cheers
1658904504

Edited 1658904781
"the last line needed to be inverted. )}; to }); Literally just a syntax error on the last line... I can't believe it. Thank you for looking into this, you've really helped me out. 
1658923773

Edited 1658923865
GiGs
Pro
Sheet Author
API Scripter
In sheet workers, there are some errors that will take down the whole sandbox, and some that will just cause a single sheet worker to fail but wont affect the others. Here, in setAttrs you were calling a variable that didnt exist (at least, that's what roll20 thought you were doing) - the way you had that set up, it was looking for a variable named genderroll, which doesnt exist. By the way, you can simplify the sheet worker. Since the roll never gets shown to the players, you can generate 0 or 1 directly. on('clicked:genderroll', function () { const gendervalue = Math.floor(Math.random() * 2); setAttrs({ gender: gendervalue, }); }); If you were keeping that if statement, a simple else suffices there: if (genderrollValue <= 5) { gendervalue = 0; } else { gendervalue = 1; }
That's much nicer looking, thanks for the formatting help.