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

Custom Character Logic Help

1744248146

Edited 1744248582
I am modifying an existing character sheet to add talents that modify a skill if taken. So you have a choice of Slicing +5% or Spirit Lore +5%.  I have the code working and it works for no checkbox and one checkbox, and I coded it so when both checkboxes are clicked, it removes the modifications and just keeps it the same as if no checkboxes are selected.  What I'd really like is when you have one checkbox selected and you click the other checkbox it unchecks the already checked checkbox. This is the skill being modified, if you add skill points, it updates attr_slicing_skill_mdr . The skill point + any modifier are written out to attr_slicing_mdr <tr data-i18n-list-item="slicing"> <td><input type="checkbox" name="attr_slicing_mdr_checkbox"></td> <td class="skill-label" data-i18n="slicing-u">Slicing(05%)</td> <td><input class="skill-input" type="text" name="attr_slicing_skill_mdr" value="5"/></td> <td><input class="skill-input" type="text" name="attr_slicing_mdr" value="@{slicing_mdr}" readonly/></td> <td><button class='new-roll' type='roll' value='&{template:coc-1} {{name=@{slicing_txt}}} {{success=[[@{slicing_mdr}]]}} {{hard=[[floor(@{slicing_mdr}/2)]]}} {{extreme=[[floor(@{slicing_mdr}/5)]]}} {{roll1=[[1d100]]}}' name='roll_slicing_mdr_check' /></td> </tr> The talent is here, written out to a talent section separate from the skill section <tr data-i18n-list-item="draevi_slicing"> <td><input type="checkbox" name="attr_dravei_slicing_mdr_checkbox" value="1"></td> <td class="talent-label" data-i18n="draevi_slicing-u">Slicing + 5%</td> <td>Gain +5% Slicing Skill</td> <td><input class="skill-input" type="text" name="attr_draevi_slicing_bonus_mdr" value="@{dravei_slicing_bonus_mdr}" readonly/></td> </tr> The sheet worker code to update the value is here on("sheet:opened add:slicing_skill_mdr change:slicing_skill_mdr add:spirit_lore_skill_mdr change:spirit_lore_skill_mdr change:dravei_slicing_mdr_checkbox change:dravei_spirit_lore_mdr_checkbox", function() { getAttrs(["slicing_mdr", "spirit_lore_mdr", "slicing_skill_mdr", "draevi_slicing_bonus_mdr", "spirit_lore_skill_mdr", "draevi_spirit_lore_bonus_mdr", "dravei_slicing_mdr_checkbox", "dravei_spirit_lore_mdr_checkbox"], function(values) { var islicing_mdr = parseInt(values.slicing_mdr) || 0; var ispirit_lore_mdr = parseInt(values.spirit_lore_mdr) || 0; var islicing_skill_mdr = parseInt(values.slicing_skill_mdr) || 5; var idravei_slicing_bonus_mdr = parseInt(values.draevi_slicing_bonus_mdr) || 5; var ispirit_lore_skill_mdr = parseInt(values.spirit_lore_skill_mdr) || 5; var idravei_spirit_lore_bonus_mdr = parseInt(values.draevi_spirit_lore_bonus_mdr) || 5; var idravei_slicing_mdr_checkbox = parseInt(values.dravei_slicing_mdr_checkbox) || 0; var idravei_spirit_lore_mdr_checkbox = parseInt(values.dravei_spirit_lore_mdr_checkbox) || 0; var islicing_mdr_total = islicing_skill_mdr; var ispirit_lore_mdr_total = ispirit_lore_skill_mdr; if ( idravei_slicing_mdr_checkbox > 0 && idravei_spirit_lore_mdr_checkbox == 0) { idravei_spirit_lore_mdr_checkbox = 0; islicing_mdr_total = islicing_skill_mdr + Math.ceil( islicing_skill_mdr * ( ( idravei_slicing_bonus_mdr ) / 100 ) ); } if ( idravei_spirit_lore_mdr_checkbox > 0 && idravei_slicing_mdr_checkbox == 0) { idravei_slicing_mdr_checkbox = 0; ispirit_lore_mdr_total = ispirit_lore_skill_mdr + Math.ceil( ispirit_lore_skill_mdr * ( ( idravei_spirit_lore_bonus_mdr ) / 100 ) ); } setAttrs ({slicing_mdr: islicing_mdr_total}); setAttrs ({spirit_lore_mdr: ispirit_lore_mdr_total}); setAttrs ({dravei_slicing_mdr_checkbox: idravei_slicing_mdr_checkbox}); setAttrs ({dravei_spirit_lore_mdr_checkbox: idravei_spirit_lore_mdr_checkbox}); }); }); I just need shove in the right direction, how do I force the one checkbox to uncheck when the other one is chosen?
1744251084
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
are these both in the same repeating item? or are they separate rows in the repeating section?
Here's the full section <!------------------------- Talents -------------------------> <div class='sheet-colrow'> <input type="checkbox" style="display:none" class="sheet-toggletalents" name="attr_toggletalents" value="1"> <div class="sheet-pulptalentssection"> <input type="checkbox" style="display:none" class="sheet-showpulp" name="attr_showpulp" value="1"> <input type="checkbox" style="display:none" class="sheet-showskills" name="attr_showskills" value="7"> <input type="checkbox" style="display:none" class="sheet-showskills" name="attr_showskills" value="1"> <input type="checkbox" style="display:none" class="sheet-showskills" name="attr_showskills" value="5"> <input type="checkbox" style="display:none" class="sheet-showskills" name="attr_showskills" value="2"> <input type="checkbox" style="display:none" class="sheet-showskills" name="attr_showskills" value="3" checked="checked"> <input type="checkbox" style="display:none" class="sheet-showskills" name="attr_showskills" value="6"> <input type="checkbox" style="display:none" class="sheet-showskills" name="attr_showskills" value="4"> <h4 class="section-head" data-i18n="talents-u">Talents</h4> <div class="sheet-talent-section" style="width: 97.7%"> <table style="width:100%"> <h3>Spiritbound Techshaper</h3> <tr> <th>A</th> <th>Talent Name</th> <th>Description</th> <th>Val</th> <tr> <tr data-i18n-list-item="draevi_slicing"> <td><input type="checkbox" name="attr_dravei_slicing_mdr_checkbox" value="1"></td> <td class="talent-label" data-i18n="draevi_slicing-u">Slicing + 5%</td> <td>Gain +5% Slicing Skill</td> <td><input class="skill-input" type="text" name="attr_draevi_slicing_bonus_mdr" value="@{dravei_slicing_bonus_mdr}" readonly/></td> </tr> <tr data-i18n-list-item="draevi_spirit_lore"> <td><input type="checkbox" name="attr_dravei_spirit_lore_mdr_checkbox" value="1"></td> <td class="talent-label" data-i18n="draevi_spirit_lore-u">Spirit Lore + 5%</td> <td>Gain +5% Spirit Lore Skill</td> <td><input class="skill-input" type="text" name="attr_draevi_spirit_lore_bonus_mdr" value="@{dravei_spirit_lore_bonus_mdr}" readonly/></td> </tr> </table> <fieldset class="repeating_talents"> <textarea name="attr_talent" style="width:99%;height:38px;font-size:90%"></textarea> </fieldset> </div> </div> </div>
1744251548
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The easy way is to give them the same name. They then act as you want without any extra work.
The checkboxes? How would I know which skill to modify then? Or something else? Sorry, still new to the code.
1744252689
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
yes, the checkboxes. You'd change the checkbox values to be the skill you want to affect: <input type="checkbox" name="attr_draevi_mdr_checkbox" value="slicing"> <input type="checkbox" name="attr_draevi_mdr_checkbox" value="spirit lore"> When the slicing one is checked, the value will be "slicing". same for the spirit lore. When neither is selected, the value will be zero.
Oh that's elegant, I like it.  Will work on it and report back, thank you!
1744253074
GiGs
Pro
Sheet Author
API Scripter
By the way. this part of your code can (and should) be altered: setAttrs ({slicing_mdr: islicing_mdr_total}); setAttrs ({spirit_lore_mdr: ispirit_lore_mdr_total}); setAttrs ({dravei_slicing_mdr_checkbox: idravei_slicing_mdr_checkbox}); setAttrs ({dravei_spirit_lore_mdr_checkbox: idravei_spirit_lore_mdr_checkbox}); to this: setAttrs ({ slicing_mdr: islicing_mdr_total, spirit_lore_mdr: ispirit_lore_mdr_total, dravei_slicing_mdr_checkbox: idravei_slicing_mdr_checkbox, dravei_spirit_lore_mdr_checkbox: idravei_spirit_lore_mdr_checkbox }); You can change several stats with a single setAttrs command.
Thank  you! Great tip.
Working great, I updated the code with the suggestions including the setAttrs I did have one question, should I store the value of the checkboxes in a variable and then do the if test on the variable, or is testing it directly okay? No corner case where it might be unset and cause an error? on("sheet:opened add:slicing_skill_mdr change:slicing_skill_mdr add:spirit_lore_skill_mdr change:spirit_lore_skill_mdr change:draevi_mdr_checkbox", function() { getAttrs(["slicing_mdr", "spirit_lore_mdr", "slicing_skill_mdr", "draevi_slicing_bonus_mdr", "spirit_lore_skill_mdr", "draevi_spirit_lore_bonus_mdr", "draevi_mdr_checkbox"], function(values) { var islicing_mdr = parseInt(values.slicing_mdr) || 0; var ispirit_lore_mdr = parseInt(values.spirit_lore_mdr) || 0; var islicing_skill_mdr = parseInt(values.slicing_skill_mdr) || 5; var idravei_slicing_bonus_mdr = parseInt(values.draevi_slicing_bonus_mdr) || 5; var ispirit_lore_skill_mdr = parseInt(values.spirit_lore_skill_mdr) || 5; var idravei_spirit_lore_bonus_mdr = parseInt(values.draevi_spirit_lore_bonus_mdr) || 5; var islicing_mdr_total = islicing_skill_mdr; var ispirit_lore_mdr_total = ispirit_lore_skill_mdr; if ( values.draevi_mdr_checkbox == "slicing" ) { islicing_mdr_total = islicing_skill_mdr + Math.ceil( islicing_skill_mdr * ( ( idravei_slicing_bonus_mdr ) / 100 ) ); } if ( values.draevi_mdr_checkbox == "spirit_lore" ) { ispirit_lore_mdr_total = ispirit_lore_skill_mdr + Math.ceil( ispirit_lore_skill_mdr * ( ( idravei_spirit_lore_bonus_mdr ) / 100 ) ); } setAttrs ({ slicing_mdr: islicing_mdr_total, spirit_lore_mdr: ispirit_lore_mdr_total }); }); });
1744260075

Edited 1744260093
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Nope, as long as the html for them is in the sheet code it will always be some value ("0", slicing, or spirit_lore).
Thank you again.
This is working great, and I can now extend its use to other backgrounds/talents for this scenario.  Thank you again for the shove in the right direction.