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

Sheet worker help

1485274776

Edited 1485278120
Matthew C
Pro
Sheet Author
I need some help with the sheet worker <label style="width: 135px">Positive Heritage</label></td> <td style="width: 140px"> <select style="width: 140px" type="text" name="attr_Heritage_Bonus"></td> <option value="0" selected>None</option> <option value="0">Strong</option> <option value="0">Durable</option> <option value="0">Swift</option> <option value="0">Precise</option> <option value="0">Smart</option> <option value="0">Authority</option> <option value="0">Keen</option> <option value="0">Lucky</option> </select> <input type="hidden" value="0" name="attr_None"> <input type="hidden" value="0" name="attr_Strong"> <input type="hidden" value="0" name="attr_Durable"> <input type="hidden" value="0" name="attr_Swift"> <input type="hidden" value="0" name="attr_Precise"> <input type="hidden" value="0" name="attr_Smart"> <input type="hidden" value="0" name="attr_Authority"> <input type="hidden" value="0" name="attr_Keen"> <input type="hidden" value="0" name="attr_Lucky"> What I need is when the choice is chosen with the same name, the value changes to 2 and if a different choice is taken the first one goes to value 0 and the new one gets to a value 2 I hear that this can be done with sheet worker, but the explanation on how to work with sheet workers is confusing me. If someone could help me with this I could do the rest based on this...so thanks in advance guys I really need your guys' help :D
1485279631
David
Sheet Author
<label style="width: 135px">Positive Heritage</label></td> <td style="width: 140px"> <select style="width: 140px" type="text" name="attr_Heritage_Bonus"></td> <option value="0" selected>None</option> <option value="1">Strong</option> <option value="2">Durable</option> <option value="3">Swift</option> <option value="4">Precise</option> <option value="5">Smart</option> <option value="6">Authority</option> <option value="7">Keen</option> <option value="8">Lucky</option> </select> <input type="hidden" value="0" name="attr_None"> <input type="hidden" value="0" name="attr_Strong"> <input type="hidden" value="0" name="attr_Durable"> <input type="hidden" value="0" name="attr_Swift"> <input type="hidden" value="0" name="attr_Precise"> <input type="hidden" value="0" name="attr_Smart"> <input type="hidden" value="0" name="attr_Authority"> <input type="hidden" value="0" name="attr_Keen"> <input type="hidden" value="0" name="attr_Lucky">
1485279686
David
Sheet Author
<script type="text/worker"> on("change:heritage_bonus", function() {    getAttrs(["heritage_bonus"], function(values) {      var hBonus = values.heritage_bonus; setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:0}); if (hBonus = 0){ setAttrs({None:2}); } if (hBonus =1){ setAttrs({Durable:2}); } if (hBonus =2){ setAttrs({Strong:2}); } if (hBonus =3){ setAttrs({Swift:2}); } if (hBonus >4){ setAttrs({Precise:2}); } if (hBonus >5){ setAttrs({Smart:2}); } if (hBonus >6){ setAttrs({Authority:2}); } if (hBonus >7){ setAttrs({Keen:2}); } if (hBonus >8){ setAttrs({Lucky:2}); }    }); }) </script>
1485279753

Edited 1485279770
David
Sheet Author
Should get you started and I am sure there is a prettier way of doing it.
1485280746
Matthew C
Pro
Sheet Author
Hmm, it seemed to change the value of durable to 2, but nothing brings it back to 0 Thanks for the help so far, at least I know people are trying to help, it is just a very confusing sheet worker from what I understand
1485283931
Matthew C
Pro
Sheet Author
<label style="width: 135px">Positive Heritage</label></td> <td style="width: 140px"> <select style="width: 140px" type="text" name="attr_Heritage_Bonus"></td> <option value="0" selected>None</option> <option value="1">Strong</option> <option value="2">Durable</option> <option value="3">Swift</option> <option value="4">Precise</option> <option value="5">Smart</option> <option value="6">Authority</option> <option value="7">Keen</option> <option value="8">Lucky</option> </select> <input type="hidden" value="0" name="attr_None"> <input type="hidden" value="0" name="attr_Strong"> <input type="hidden" value="0" name="attr_Durable"> <input type="hidden" value="0" name="attr_Swift"> <input type="hidden" value="0" name="attr_Precise"> <input type="hidden" value="0" name="attr_Smart"> <input type="hidden" value="0" name="attr_Authority"> <input type="hidden" value="0" name="attr_Keen"> <input type="hidden" value="0" name="attr_Lucky"> <script type="text/worker"> on("change:heritage_bonus", function() { getAttrs(["heritage_bonus"], function(values) { var hBonus = values.heritage_bonus; setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:0}); if (hBonus < 0){ setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:0}); } if (hBonus > 0){ setAttrs({None:0,Strong:2,Durable:0,Swift:0,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:0}); } if (hBonus > 1){ setAttrs({None:0,Strong:0,Durable:2,Swift:0,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:0}); } if (hBonus > 2){ setAttrs({None:0,Strong:0,Durable:0,Swift:2,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:0}); } if (hBonus > 3){ setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:2,Smart:0,Authority:0,Keen:0,Lucky:0}); } if (hBonus > 4){ setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:2,Authority:0,Keen:0,Lucky:0}); } if (hBonus > 5){ setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:0,Authority:2,Keen:0,Lucky:0}); } if (hBonus > 6){ setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:0,Authority:0,Keen:2,Lucky:0}); } if (hBonus > 7){ setAttrs({None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:2}); } }); }) </script> This seems to work but is very dirty coding, but at least it works :D
1485294548
David
Sheet Author
The first setAttrs before the ifs should set everything to 0. Set the value of the Durable to  2 and comment out the ifs and run the page see if it resets to 0.
1485296001
Matthew C
Pro
Sheet Author
if I get rid of the ifs then the entire thing breaks
1485296644

Edited 1485296832
Jakob
Sheet Author
API Scripter
<label style="width: 135px">Positive Heritage</label></td> <td style="width: 140px"> <select style="width: 140px" type="text" name="attr_Heritage_Bonus"></td> <option value="None" selected>None</option> <option value="Strong">Strong</option> <option value="Durable">Durable</option> <option value="Swift">Swift</option> <option value="Precise">Precise</option> <option value="Smart">Smart</option> <option value="Authority">Authority</option> <option value="Keen">Keen</option> <option value="Lucky">Lucky</option> </select> <input type="hidden" value="0" name="attr_None"> <input type="hidden" value="0" name="attr_Strong"> <input type="hidden" value="0" name="attr_Durable"> <input type="hidden" value="0" name="attr_Swift"> <input type="hidden" value="0" name="attr_Precise"> <input type="hidden" value="0" name="attr_Smart"> <input type="hidden" value="0" name="attr_Authority"> <input type="hidden" value="0" name="attr_Keen"> <input type="hidden" value="0" name="attr_Lucky"> <script type="text/worker"> on("change:heritage_bonus", function() {    getAttrs(["heritage_bonus"], function(values) {  var attrs = {None:0,Strong:0,Durable:0,Swift:0,Precise:0,Smart:0,Authority:0,Keen:0,Lucky:0}; if (_.has(attrs, values.heritage_bonus)) { attrs[values.heritage_bonus] = 2; } setAttrs(attrs);    }); }); </script> Unless, for some reason, it's not possible for Heritage_Bonus to have an actual descriptive value instead of a cryptic number, in which case one would need an extra variable. By the way, some pointers: Test for equality in Javascript with == (or, better, ===). '=' is the assignment operator. (By the way, this is the reason things never get reset to zero). With asynchronous operations like setAttrs, doing things "first" is not exactly safe, because commands issued first may be executed later.
1485297297
David
Sheet Author
Test for equality in Javascript with == (or, better, ===). '=' is the assignment operator. (By the way, this is the reason things never get reset to zero). That will teach me not to copy/paste/type on a tiny phone screen while in a hurry.
1485298871
Jakob
Sheet Author
API Scripter
David said: Test for equality in Javascript with == (or, better, ===). '=' is the assignment operator. (By the way, this is the reason things never get reset to zero). That will teach me not to copy/paste/type on a tiny phone screen while in a hurry. Ah, so that's where the random '>' in the later ifs come from :D. Writing code on a phone screen is an advanced form of self-flagellation...
1485345176
Matthew C
Pro
Sheet Author
Thanks Jakob, but I need the Strong attribute to increase my strength, the durable attribute to change my durability etc. So with the way you have it, it would be to print out the value of heritage bonus which is not used like that. Thanks for trying though :D Or am I being an idiot and not understanding it (I am not at home so I cannot test it right now, I will test it later if you say this is what it will do) :D :D
1485346468
David
Sheet Author
It works as understand the problem.
1485346771
Jakob
Sheet Author
API Scripter
Matthew C said: Thanks Jakob, but I need the Strong attribute to increase my strength, the durable attribute to change my durability etc. So with the way you have it, it would be to print out the value of heritage bonus which is not used like that. Thanks for trying though :D Or am I being an idiot and not understanding it (I am not at home so I cannot test it right now, I will test it later if you say this is what it will do) :D :D I have no idea what you're saying, but apparently I understand things the same way David does... If, after testing, you discover that this doesn't do what it ought to do, perhaps you can explain again what it is precisely that it should do.
1485347406
David
Sheet Author
Oh I think I get it now he wants to add the plus +2  to particular stat which he made no reference to in his original post.
1485349673
David
Sheet Author
Is this what you are looking for ?
1485351289

Edited 1485353529
Jakob
Sheet Author
API Scripter
Hmm, that makes a lot of sense. Here's a modified version for the above interpretation: <label style="width: 135px">Positive Heritage</label></td> <td style="width: 140px"> <select style="width: 140px" type="text" name="attr_heritage_bonus"></td> <option value="none" selected>None</option> <option value="strength">Strong</option> <option value="durability">Durable</option> <option value="swiftness">Swift</option> <option value="precision">Precise</option> <option value="smartness">Smart</option> <option value="authority">Authority</option> <option value="keenness">Keen</option> <option value="luck">Lucky</option> </select><br> Strength<input type="number" value="0" name="attr_strength_base"> Durability<input type="number" value="0" name="attr_durability_base"> Swiftness<input type="number" value="0" name="attr_swiftness_base"> Precision<input type="number" value="0" name="attr_precision_base"> Smartness<input type="number" value="0" name="attr_smartness_base"> Authority<input type="number" value="0" name="attr_authority_base"> Keenness<input type="number" value="0" name="attr_keenness_base"> Luck<input type="number" value="0" name="attr_luck_base"><br> Modified Strength  <span name="attr_strength"></span><br> Modified Durability  <span name="attr_durability"></span><br> Modified Swiftness  <span name="attr_swiftness"></span><br> Modified Precision  <span name="attr_precision"></span><br> Modified Smartness  <span name="attr_smartness"></span><br> Modified Authority  <span name="attr_authority"></span><br> Modified Keenness  <span name="attr_keenness"></span><br> Modified Luck  <span name="attr_luck"></span> <script type="text/worker"> on("sheet:opened change:heritage_bonus change:strength_base change:durability_base change:swiftness_base change:precision_base change:smartness_base change:authority_base change:keenness_base change:luck_base", function () {   var attrs = ['strength', 'durability', 'swiftness', 'precision', 'smartness', 'authority', 'keenness', 'luck'],     attrs_base = _.map(attrs, str => str + '_base');   getAttrs(_.union(attrs_base, ['heritage_bonus']), function (values) {     var finalAttrs = _.reduce(values, function (m, v, k) {       if (k !== 'heritage_bonus') {         m[attrs[_.indexOf(attrs_base, k)]] = v;       }       return m;     }, {});     if (_.has(finalAttrs, values.heritage_bonus)) {       finalAttrs[values.heritage_bonus] = parseInt(finalAttrs[values.heritage_bonus]) + 2;     }     setAttrs(finalAttrs);   }); }); </script> Edited for sensible attribute names.
1485368709
Matthew C
Pro
Sheet Author
Thanks Jakob, the earlier version (the one I was unsure of) is exactly what I was looking for, it just looked strange and my knowledge of coding was not enough to see it for what it was :D So thanks for trying to nterpret what I meant and give me a second version, you guys are the greatest :D
1485507035
Matthew C
Pro
Sheet Author
Now comes a very difficult question... How can I unhide things by using a sheetworker I believe it should be possible. This is what I mean: I have 1 drop down menu: <select style="width: 110px" type="text" name="attr_Faction_Choice"></td> <option value="0" selected>Magical</option> <option value="0">Primal</option> <option value="0">Technological</option> </select> And then what I want it to do is show a drop down menu for Magical. But if you switch it to primal I want it to hide the magical dropdown and show the primal dropdown and same for technological. I am pretty sur I read that this was possible, but I cannot seem to be able to find out how. I believe if I have the code to do this I can make my entire sheet finally :D as the hide command would be used in many many places. Thanks in advance guys :D
1485517653
Kryx
Pro
Sheet Author
API Scripter
You'd have to use css and hidden inputs. <input type="hidden" name="attr_Faction_Choice" class="faction-choice-toggle"> <select style="width: 110px" type="text" name="attr_Faction_Choice"></td> <option value="magical" selected>Magical</option> <option value="primal">Primal</option> <option value="technological">Technological</option> </select> <div class="magical"> //MAGIC STUFF HERE </div> <div class="primal"> //MAGIC STUFF HERE </div> <div class="technological"> //MAGIC STUFF HERE </div> CSS: .sheet-faction-choice-toggle:not([value='magical']) ~ .sheet-magical, .sheet-faction-choice-toggle:not([value='primal']) ~ .sheet-primal, .sheet-faction-choice-toggle:not([value='technological']) ~ .sheet-technological { display: none; }
1485517969
Matthew C
Pro
Sheet Author
Thanks will take a look at that :D
1485519258

Edited 1485520245
Matthew C
Pro
Sheet Author
<input type="hidden" name="attr_Faction_Choice" class="faction-choice-toggle"> <select style="width: 110px" type="text" name="attr_Faction_Choice"></td> <option value="magical" selected>Magical</option> <option value="primal">Primal</option> <option value="technological">Technological</option> </select> <td style="width:101px"> <label>Name</label></td> <td> <input style="float:left;width: 200px" type="text" name="attr_character_name"></td> <td style="width: 110px"> <label style="width: 110px">Specialization</label></td> <td style="width: 130px"> <select style="width: 130px" type="text" name="attr_magical"></td> <option value="None" selected>None</option> </select> <div class="magical"> <select style="width: 130px" name="attr_magical"></td> <option value="None" selected>None</option> <option value="AgSpec">Agility</option> <option value="DuSpec">Durability</option> <option value="ViSpec">Vigor</option> <option value="AdSpec">Advantage</option> <option value="NiSpec">Nimbleness</option> <option value="CoSpec">Comprehension</option> <option value="EsSpec">Essence</option> <option value="DiSpec">Discernment</option> </select> </div> <div class="primal"> <select style="width: 130px" name="attr_primal"</td> <option value="None" selected>None</option> <option value="AgSpec">Agility</option> <option value="DuSpec">Durability</option> <option value="ViSpec">Vigor</option> <option value="AdSpec">Advantage</option> <option value="NiSpec">Nimbleness</option> <option value="CoSpec">Comprehension</option> <option value="EsSpec">Essence</option> <option value="DiSpec">Discernment</option> </select> </div> <div class="technological"> <select style="width: 130px" name="attr_technological"></td> <option value="None" selected>None</option> <option value="AgSpec">Agility</option> <option value="DuSpec">Durability</option> <option value="ViSpec">Vigor</option> <option value="AdSpec">Advantage</option> <option value="NiSpec">Nimbleness</option> <option value="CoSpec">Comprehension</option> <option value="EsSpec">Essence</option> <option value="DiSpec">Discernment</option> </select> </div> .sheet-faction-choice-toggle:not([value='magical']) ~ .sheet-magical, .sheet-faction-choice-toggle:not([value='primal']) ~ .sheet-primal, .sheet-faction-choice-toggle:not([value='technological']) ~ .sheet-technological { display: none; } This is what I have The bottom part is in the css of course, but it does nothing, so I must be doing something wrong The names and values of the 3 dropdowns are filler for now :D
1485520562

Edited 1485520612
David
Sheet Author
attr_Faction_Choice input has to be type="check" does it not
1485522224

Edited 1485522299
Kryx
Pro
Sheet Author
API Scripter
You changed the structure of the dom (html elements). The css is dependent on the dom. Where is the original select? That depicts how the css should be structured. Alternatively you can put the hidden input at the top level of your html structure with all other variables. Example: //variables go here <input type="hidden" name="attr_Faction_Choice" class="faction-choice-toggle"> //other inputs <div class="page"> <table> <tr> <td> <div class="magical"></div> </td> </tr> </table> </div> And then the css would be: .sheet-faction-choice-toggle:not([value='magical']) ~ div .sheet-magical, .sheet-faction-choice-toggle:not([value='primal']) ~ div .sheet-primal, .sheet-faction-choice-toggle:not([value='technological']) div ~ .sheet-technological { display: none; } The inputs should not be checkboxes, no.
1485526982
Matthew C
Pro
Sheet Author
This is the entire HTML section <divstyle="text-align: left ; width: 828px ; margin-top:10px;margin-bottom: -10px">Step Two, Faction, Name and Specialization </div> <div style="position: relative ; z-index: 5 ; color: #85D6FF ; float: right ; bottom: 16px ; margin-bottom: -10px ; text-align: right ; font-weight: bold">Show Step Two     <input type="checkbox" title="steptwo-show" name="attr_steptwo-show" value="1" style="opacity: 1 ; width: 16px ; height: 16px ; position: relative ; top: 0px ; right: 5px ; margin: 0px ; cursor: pointer ; z-index: 1;"> <div> <input type="hidden" name="attr_Faction_Choice"> <div> <table border="1" style="position: relative;width: 838px;left: 8px;float: right;color: black;margin-top: 15px;text-align:left;"> <tbody> <tr> <td style="width: 110px"> <label style="width: 110px">Specialization</label> <td style="width: 101px"> <select style="width: 110px" type="text" name="attr_Faction_Choice"> <option value="magical" selected>Magical</option> <option value="primal">Primal</option> <option value="technological">Technological</option> </select> <td style="width:101px"> <label>Name</label></td> <td> <input style="float:left;width: 200px" type="text" name="attr_character_name"></td> <td> <div> <select style="width: 130px" type="hidden" name="attr_magical"> <option value="None" selected>None</option> <option value="AgSpec">Agility</option> <option value="DuSpec">Durability</option> <option value="ViSpec">Vigor</option> <option value="AdSpec">Advantage</option> <option value="NiSpec">Nimbleness</option> <option value="CoSpec">Comprehension</option> <option value="EsSpec">Essence</option> <option value="DiSpec">Discernment</option> </div> <div> <select style="width: 130px" name="attr_primal"> <option value="None" selected>None</option> <option value="AgSpec">Agility</option> <option value="DuSpec">Durability</option> <option value="ViSpec">Vigor</option> <option value="AdSpec">Advantage</option> <option value="NiSpec">Nimbleness</option> <option value="CoSpec">Comprehension</option> <option value="EsSpec">Essence</option> <option value="DiSpec">Discernment</option> </select> </div> <div> <select style="width: 130px" name="attr_technological"> <option value="None" selected>None</option> <option value="AgSpec">Agility</option> <option value="DuSpec">Durability</option> <option value="ViSpec">Vigor</option> <option value="AdSpec">Advantage</option> <option value="NiSpec">Nimbleness</option> <option value="CoSpec">Comprehension</option> <option value="EsSpec">Essence</option> <option value="DiSpec">Discernment</option> </select> </div> </td> </tr> </tbody> </table> </div> The above now works, however there is one problem, the chosen selections are remembered meaning that the value of ALL three dropdowns are being used. So it is halfway there I would say, it now only shows the dropdown I want it to show, but the ones that are hidden are still impacting the statistics :( Is there a way to make them revert back to the NONE selection when they are hidden?
1485527229
Matthew C
Pro
Sheet Author
Nvm, I gave the three dropdown the same attribute, and they it only allows one, the moment I change to a different one and choose something it resets the other to None again as that is the standard choice which = 0 :D
1485527414
Kryx
Pro
Sheet Author
API Scripter
So it does what you want, correct?
1485527632
Matthew C
Pro
Sheet Author
It does yes, and now I can use the sheetworker script to make the dropdowns do what I want, You guys are awesome. I am saving all of these forum threads so I can add a thanks to all you guys for all your help :D
1485527707
Kryx
Pro
Sheet Author
API Scripter
Cool, best of luck!