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

Is there something wrong with this sheet worker?

Hi folks. I'm trying to get a sheet worker to read the values in a set of fields, do some math on the result and display the final answer in a text field. Here's what I have so far- //when the sheet loads or the relevent values change on("change:repeating_experience:experiencetype change:repeating_experience:skilltitlebody change:repeating_experience:skilltitlemind change:repeating_experience:skilltitleeq change:repeating_experience:skilltitlequick change:repeating_experience:expyearstart change:repeating_experience:expyearend sheet:opened", function() { //get the attributes from the repeating section that's changed getAttrs([ "repeating_experience_experiencetype", "repeating_experience_skilltitlebody", "repeating_experience_skilltitlemind", "repeating_experience_skilltitleeq", "repeating_experience_skilltitlequick", "repeating_experience_expyearstart", "repeating_experience_expyearend" ], function(values) { //setup a bunch of variables let swexperiencetype = parseInt(values.repeating_experience_experiencetype) ||0; let swskilltitlebody = parseInt(values.repeating_experience_skilltitlebody) ||0; let swskilltitlemind = parseInt(values.repeating_experience_skilltitlemind) ||0; let swskilltitleeq = parseInt(values.repeating_experience_skilltitleeq) ||0; let swskilltitlequick = parseInt(values.repeating_experience_skilltitlequick) ||0; let swexpyearstart = parseInt(values.repeating_experience_expyearstart) ||0; let swexpyearend = parseInt(values.repeating_experience_expyearend) ||0; //do some math let yearsspent = swexpyearend - swexpyearstart; let expovertime = Math.round(yearsspent * swexperiencetype); let xpspent = (swskilltitlebody + 1) + (swskilltitlemind + 1) + (swskilltitleeq + 1) + (swskilltitlequick + 1); let xpremaining = expovertime - xpspent; //pass the result of the math on to the expleftdisplay text field setAttrs({ expleftdisplay: xpremaining }) }); });
This is the part of the sheet this worker is relating to: <div class="sheet-experience"> <h1 class="sheet-section">Experiences</h1> <table width="100%" class="t2"> <thead> <tr> <th width="28%">General</th> <th width="18%">Body Focus</th> <th width="18%">Mind Focus</th> <th width="18%">EQ Focus</th> <th width="18%">Quick Focus</th> </tr> </thead> </table> <fieldset class="repeating_experience"> <table width="100%" class="t2"> <tbody> <tr> <td colspan="3"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #D0D3D4;" name="attr_Skill"> </td> <td bgcolor="#F5B7B1" colspan="4"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_SkillBody"> </td> </td> <td bgcolor="#85C1E9" colspan="4"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4E6F1;" name="attr_SkillMind"> </td> </td> <td bgcolor="#48C9B0" colspan="4"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4EFDF;" name="attr_SkillEQ"> </td> </td> <td bgcolor="#F5B7B1" colspan="4"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F6DDCC;" name="attr_SkillQuick"> </td> </tr> <tr> <td colspan="3" bgcolor="#D0D3D4" name="attr_Skill-1"> <select name="attr_ExperienceType"> <option selected disabled>Select a field</option> <option value="1">Acadmic</option> <option value="0.5">White Collar</option> <option value="1">Labor</option> <option value="0.5">Hobby</option> <option value="2">Military</option> <option value="1">Protective Services</option> <option value="2">Athletic</option> <option value="1">Medical</option> </select> </td> <td bgcolor="#F5B7B1" colspan="4"> <select name="attr_SkillTitleBody"> <option selected disabled></option> <option value="-2">Untrained</option> <option value="0">Novice</option> <option value="1">Apprentice</option> <option value="2">Journeyman</option> <option value="3">Master</option> <option value="4">Grandmaster</option> <option value="5">Grandmaster + 1</option> <option value="6">Grandmaster + 2</option> <option value="7">Grandmaster + 3</option> <option value="8">Grandmaster + 4</option> </select> </td> <td bgcolor="#85C1E9" colspan="4"> <select name="attr_SkillTitleMind"> <option selected disabled></option> <option value="-2">Untrained</option> <option value="0">Novice</option> <option value="1">Apprentice</option> <option value="2">Journeyman</option> <option value="3">Master</option> <option value="4">Grandmaster</option> <option value="5">Grandmaster + 1</option> <option value="6">Grandmaster + 2</option> <option value="7">Grandmaster + 3</option> <option value="8">Grandmaster + 4</option> </select> </td> <td bgcolor="#48C9B0" colspan="4"> <select name="attr_SkillTitleEQ"> <option selected disabled></option> <option value="-2">Untrained</option> <option value="0">Novice</option> <option value="1">Apprentice</option> <option value="2">Journeyman</option> <option value="3">Master</option> <option value="4">Grandmaster</option> <option value="5">Grandmaster + 1</option> <option value="6">Grandmaster + 2</option> <option value="7">Grandmaster + 3</option> <option value="8">Grandmaster + 4</option> </select> </td> <td bgcolor="#F5B041" colspan="4"> <select name="attr_SkillTitleQuick"> <option selected disabled></option> <option value="-2">Untrained</option> <option value="0">Novice</option> <option value="1">Apprentice</option> <option value="2">Journeyman</option> <option value="3">Master</option> <option value="4">Grandmaster</option> <option value="5">Grandmaster + 1</option> <option value="6">Grandmaster + 2</option> <option value="7">Grandmaster + 3</option> <option value="8">Grandmaster + 4</option> </select> </td> </tr> <!--input type="hidden" name="attr_expspent" value="@{skilltitlebody + 1} + @{skilltitlemind + 1} + @{skilltitleeq + 1} + @{skilltitlequick + 1}"--> <tr> <td bgcolor="#eb34d8"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_expyearstart" size = "4" maxLength = "4"> </td> <td bgcolor="#eb34d8"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_expyearend" size = "4" maxLength = "4"> </td> <!--input type="hidden" name="attr_YearDiff" value="@{ExpYearEnd} - @{expyearstart}"> <input type="hidden" name="attr_ExpPoints" value="@{YearDiff}*@{experiencetype}"> <input type="hidden" name="attr_ExpLeft" value="@{exppoints} - @{expspent}"--> <td bgcolor="#eb34d8"> <input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_expleftdisplay" size = "4" maxLength = "4" disabled> </td> <td bgcolor="#F5B7B1"> <input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_SkillRatingBody" value="@{Body} + @{SkillTitleBody}" disabled> </td> <td bgcolor="#F5B7B1"> <button type="roll" title="Roll against Body" value="!continuum @{Skill}|@{SkillRatingBody}|[[ ?{Modifiers not including IP|0} - @{IPTOTal}]]"></button> </td> <td bgcolor="#F5B7B1"> <!--input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_SkillProgressBody" value="0" min="0"--> </td> <td bgcolor="#F5B7B1"> <!--input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_SkillProgressMax" value="(@{SkillTitleBody} + 1) * 10" disabled--> </td> <td bgcolor="#85C1E9"> <input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4E6F1;" name="attr_SkillRatingMind" value="@{Mind} + @{SkillTitleMind}" disabled> </td> <td bgcolor="#85C1E9"> <button type="roll" title="Roll against Mind" value="!continuum @{Skill}|@{SkillRatingMind}|[[ ?{Modifiers not including IP|0} - @{IPTOTal}]]"></button> </td> <td bgcolor="#85C1E9"> <!--input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4E6F1;" name="attr_SkillProgressMind" value="0" min="0"--> </td> <td bgcolor="#85C1E9"> <!--input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4E6F1;" name="attr_SkillProgressMax" value="(@{SkillTitleMind} + 1) * 10" disabled--> </td> <td bgcolor="#48C9B0"> <input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4EFDF;" name="attr_SkillRatingEQ" value="@{EQ} + @{SkillTitleEQ}" disabled> </td> <td bgcolor="#48C9B0"> <button type="roll" title="Roll against EQ" value="!continuum @{Skill}|@{SkillRatingEQ}|[[ ?{Modifiers not including IP|0} - @{IPTOTal}]]"></button> </td> <td bgcolor="#48C9B0"> <!--input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4EFDF;" name="attr_SkillProgressEQ" value="0" min="0"--> </td> <td bgcolor="#48C9B0"> <!--input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #D4EFDF;" name="attr_SkillProgressMax" value="(@{SkillTitleEQ} + 1) * 10" disabled--> </td> <td bgcolor="#F5B041"> <input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F6DDCC;" name="attr_SkillRatingQuick" value="@{Quick} + @{SkillTitleQuick}" disabled> </td> <td bgcolor="#F5B041"> <button type="roll" title="Roll against Quick" value="!continuum @{Skill}|@{SkillRatingQuick}|[[ ?{Modifiers not including IP|0} - @{IPTOTal}]]"></button> </td> <td bgcolor="#F5B041"> <!--input type="number" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F6DDCC;" name="attr_SkillProgressQuick" value="0" min="0"--> </td> <td bgcolor="#F5B041"> </td> </tr> </tbody> </table> </fieldset> </div> And before anyone yells about me about grids vs tables, yes I know. I'd use grids if I knew how.
1706261670
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
There's a couple things I notice: I wouldn't put a sheet open listener here. There's nothing that needs to happen on sheet open as all of this is dependent on attribute changes. Mixing repeating listeners and non repeating listeners when using the short repeating section syntax will cause the sheetworker to fail and crash when the non repeating listener triggers In general I'm not a big fan of the short repeating attribute syntax. I much prefer being explicit with the row IDs and avoid using the short form in all of my sheets. Beyond those points though, what is the sheetworker doing wrong or how is it failing?
1706262405

Edited 1706262644
vÍnce
Pro
Sheet Author
Hi Tuck.  Does it work?  ;-) I would recommend dropping sheet:opened for this worker.  It's my understanding that changes within a repeating section's attribute pass the rowid which is needed to get attribute values for that row.  getSectionIDs can grab all the rows if/when that's needed.  This worker is only grabbing a given row, so running on sheet:opened it will not have a rowid to work and fail to actually calculate 'expleftdisplay'. Other than that, it looks good to me. lol edit: what Scott says. ;P edit2: WOW! the OP grew while I was responding.
1706263523
vÍnce
Pro
Sheet Author
<input type="text" STYLE="color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name="attr_expleftdisplay" size = "4" maxLength = "4" disabled> Are you having a problem writing to expleftdisplay? I believe that there could be an issue trying to write to a disabled attribute.  Try changing it to "readonly".
1706267245

Edited 1706267341
GiGs
Pro
Sheet Author
API Scripter
It looks like you are trying to set an attribute that is inside the repeating section, without using the proper syntax for it. If I'm following your intention correctly, this function setAttrs({ expleftdisplay: xpremaining }) should be setAttrs({ repeating_experience_expleftdisplay: xpremaining }); For the record, it helps to state what you are expecting to happen, and what actually is happening (if anything).
1706269607

Edited 1706356545
GiGs
Pro
Sheet Author
API Scripter
ALSO, sheet workers cant change disabled fields (Edit: I hadn't seen Vince's last reply when I wrote this), so you'll want to change this: < input type = "text" STYLE = "color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name = "attr_expleftdisplay" size = "4" maxLength = "4" disabled > to < input type = "text" STYLE = "color: #1C2833; font-family: Verdana; font-size: 12px; background-color: #F9EBEA;" name = "attr_expleftdisplay" size = "4" maxLength = "4" readonly > (Personally I'd replace those style statements with css classes, and replace the table commends with CSS Grid (which is easier!) but that's not relevant to this situation.) Size and maxLength might not do anything on roll20 btw.
Thanks so much all of you. I'll try those suggestions today.
Your advice was all great. The worker is working now. My math is all kinds of messed up, but that's on me.