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

trouble transferring one attribute to another

I'm in a repeating section, and I'm loading attributes for an inventory item after looking them up (keyed on item name) in a little object array in a worker script. Following a hint picked up on this board somewhere, I'm using the javascript to load an attribute that's tied to a hidden input field, and then using value="@{attr}" to display the attribute in a non-editable field.  Here's the actual code snippet: ... <fieldset class="repeating_bludgeon">     <select class="sheet-input-itemname" name="attr_bludgeon-name" value="name">         <option>(select one></option>         <option>Club</option>         <option>Mace</option>     </select>     <input type="text"   class="sheet-input-damage"   name="attr_bludgeon-hidden-damage" value="0d6"  hidden />     <input type="text"   class="sheet-input-damage"   name="attr_bludgeon-damage"        value='@{bludgeon-hidden-damage}' disabled /> </fieldset> ... <script type="text/worker"> on ("change:repeating_bludgeon:bludgeon-name", function(eventInfo) { let RID = eventInfo.sourceAttribute.slice(19,39); getAttrs(['repeating_bludgeon_bludgeon-name'], function(values) { let club = {name:"Club", TL:"1", damage:"2d6", weight:"3", cost:"0", ap:"0" }; let mace = {name:"Mace", TL:"1", damage:"2d6+2", weight:"3", cost:"20", ap:"0" }; let bludgeons = [club, mace]; for (i = 0 ; i < bludgeons.length ; i++) { if (bludgeons[i].name == values['repeating_bludgeon_bludgeon-name']) { setAttrs({['repeating_bludgeon_'+RID+'_bludgeon-hidden-TL']: bludgeons[i].TL, ['repeating_bludgeon_'+RID+'_bludgeon-hidden-damage']: String(bludgeons[i].damage), ['repeating_bludgeon_'+RID+'_bludgeon-hidden-weight']: bludgeons[i].weight}); } } }) }) </script> The String() on the damage is from an attempt to fix the problem.   Which is... When I run this, and select "club", what ends up appearing in the damage textbox is "26", not "2d6".  When I select mace, it's "28" - and since 8 = "6+2", I'm pretty sure that something somewhere along the way is attempting to either evaluate "2d6", or at least clean it up and make it look like a presentable number (stripping the "d" and even doing the math!) It's not the javascript. If I get rid of the "hidden"/"disabled" thing, and just load an enabled, visible field direct from js, it works properly, so I know js is delivering the string the way it is supposed to. I will accept any/all input, advice, (or even Gibbs-slaps if its something silly I should have noticed).  Thanks in advance.
1547388022
Jakob
Sheet Author
API Scripter
Okay, that's not how you're supposed to do it. You can just a readonly field like this and display it directly:     <input type="text" class="sheet-input-damage" name="attr_bludgeon-damage" value='0d6' readonly /> This will also solve your problem of displaying it correctly – using a disabled field in this way will make Roll20 try to compute a numerical value for "2d6", which is how you (somehow) end up with 26. Then you can just set bludgeon-damage directly. BTW, since your event starts in a repeating section, you do not need to capture the ID (but it doesn't hurt either): on ("change:repeating_bludgeon:bludgeon-name", function(eventInfo) { getAttrs(['repeating_bludgeon_bludgeon-name'], function(values) { let club = {name:"Club", TL:"1", damage:"2d6", weight:"3", cost:"0", ap:"0" }; let mace = {name:"Mace", TL:"1", damage:"2d6+2", weight:"3", cost:"20", ap:"0" }; let bludgeons = [club, mace]; for (i = 0 ; i < bludgeons.length ; i++) { if (bludgeons[i].name == values['repeating_bludgeon_bludgeon-name']) { setAttrs({'repeating_bludgeon_bludgeon-hidden-TL': bludgeons[i].TL, 'repeating_bludgeon_bludgeon-damage':     bludgeons[i].damage, 'repeating_bludgeon_bludgeon-hidden-weight': bludgeons[i].weight}); } } }) })