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: Using one attribute to call the value of a similarly named attribute

1565393452
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Doing a simple Attribute + Skill roller that a player can select any combination of Attribute + any Skill. Trying to find the easiest way to set that up. I tried doing it with macros but not much luck. I currently have the following attributes: rollSkill (Is set to a string matching the appropriate skill (ie. Athletics, Medicine) rollAttr (Is set to a string matching a attribute (ie. Might, Intelligence) I'm hoping that I can call either of these attributes to then point to the numerical value of their respective attributes, which are labeled like attr_Athletics, attr_Medicine, attr_Might, attr_Intelligence.  Can I do this more directly or do I need to do an if/then chain? 
1565395092

Edited 1565395459
GiGs
Pro
Sheet Author
API Scripter
how are you calling this? a single input, a a bunch of inputs in the sheet, a repeating sections? My first inclination would be to create an array of skill names, and an array of attribute names. Call those arrays skills  and attributes . You then use them in the getAttrs line of the sheet worker, along with the attribute and skill selection input, something like getAttrs([...attributes, rollSkill],function(values) { getAttrs([...skills, rollskill],function(values) { The ... is the spread operator: it tells roll20 to expand that array into its individual items and place them here.  Now you can get the value of the input_skill to get the skill value and save it in a hidden attribute.  const skill_name = values.rollSkill; const skill_value = values[skill_name]; Since your attributes are named conveniently, you can get their value this way. and then save it with setAttrs as usual.
1565395435

Edited 1565395603
GiGs
Pro
Sheet Author
API Scripter
Just remembered, you will want to put the skills and attributes arrays before the change lines, and have them all listed there. Bercause you want the values updated when any of the skills or attributes changed. One way to do this is const skills = [/* all your skills here */]; on(`change:${skills.join(' change:')} change:rollskill  sheet:opened`,  function() {        getAttrs([...skills, rollSkill],function(values) {            const skill_name = values.rollSkill;            const skill_value = values[skill_name];        setAttrs({ rollskillvalue: skill_value });        }); }); change rollskillvalue to the name of the input where your store the value. The skills.join part will build the change line for all the skills. 
1565395630
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Thinking of calling this onChange, the Skill/Attribute variable would be set when they make a new selection and prime for when they make a sheet roll. 
1565395874
GiGs
Pro
Sheet Author
API Scripter
I'm not sure what you;re calling there? html would help. What are they selecting? It'll have to wait till tomorrow though, I'm off to bed.
1565396698

Edited 1565396744
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
HTML <a href="https://pastebin.com/cRTEsHvY" rel="nofollow">https://pastebin.com/cRTEsHvY</a> CSS <a href="https://pastebin.com/h5bpzGvD" rel="nofollow">https://pastebin.com/h5bpzGvD</a> The labels themselves are selectable, the checkboxes are a kind of Proficiency check
1565436962
GiGs
Pro
Sheet Author
API Scripter
I was kinda hoping you'd post the html for the specific bit needed to understand this question.&nbsp;
1565446915
GiGs
Pro
Sheet Author
API Scripter
I had a look at this &nbsp;&lt;div class="rowflex"&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="checkbox" class="radio-path order1" name="attr_path-Academics"&gt;&lt;span&gt;&lt;/span&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;label class="text-button inline order2"&gt;&lt;input type="radio" class="labelradio invisible" name="attr_rollSkill" value="Academics"&gt;&lt;span data-il8n="Academics"&gt;Academics&lt;/span&gt;&lt;/label&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="text" class="input input-skill order3"&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="inline dotcontainer order4"&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="radio" class="radio-dots invisible" name="attr_Academics" value="0" checked="checked"&gt;&lt;span&gt;&lt;/span&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="radio" class="radio-dots" name="attr_Academics" value="1"&gt;&lt;span&gt;&lt;/span&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="radio" class="radio-dots" name="attr_Academics" value="2"&gt;&lt;span&gt;&lt;/span&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="radio" class="radio-dots" name="attr_Academics" value="3"&gt;&lt;span&gt;&lt;/span&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="radio" class="radio-dots" name="attr_Academics" value="4"&gt;&lt;span&gt;&lt;/span&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type="radio" class="radio-dots" name="attr_Academics" value="5"&gt;&lt;span&gt;&lt;/span&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt; So it looks like all your skills are a single radio button, rollSkill. So your highlighting the one that is currently selected. And each one also has a radio button showing its value. That said, the technique I described above should should work with no problem. You just need to create two hidden inputs: one for current attribute value, and one for current skill value. Lets say we call them active_attribute, and active_skill. Put these anywhere in your sheet. &lt;input type="hidden" name="attr_activeattribute" value="0"&gt; &lt;input type="hidden" name="attr_activeskill" value="0"&gt; And add these two sheet workers For skills: const skills = ['Academics', 'Athletics', /* rest of your skills here */]; on(`change:${skills.join(' change:')} change:rollskill&nbsp; sheet:opened`, &nbsp;function() {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;getAttrs([...skills, rollSkill],function(values) {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const skill_name = values.rollSkill;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const skill_value = values[skill_name]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs({ active_skill: skill_value });&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}); }); For attributes const attributes = [/* all your attributes here */]; on(`change:${attributes.join(' change:')} change:rollattribute&nbsp; sheet:opened`, &nbsp;function() {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;getAttrs([...attributes, rollAttribute],function(values) {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs({ active_attribute: values[values.rollAttribute] });&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}); }); And if I'm understanding the code, that should do the trick.
1565470740

Edited 1565471023
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Getting errors in the console, this happens in the flavors of both Skills and Attributes: ReferenceError: rollAttribute is not defined &nbsp; &nbsp; at Array.eval (eval at messageHandler (sheetsandboxworker.js?1565470367924:698), &lt;anonymous&gt;:14:30) &nbsp; &nbsp; at self.trigger (sheetsandboxworker.js?1565470367924:110) &nbsp; &nbsp; at messageHandler (sheetsandboxworker.js?1565470367924:702) ::EDIT:: Figured it out, just needed to wrap the attribute in '' Looks like its working now. Amazing! Thanks GiGs
1565472859
GiGs
Pro
Sheet Author
API Scripter
oh yes, well spotted. You're welcome :)
1565495072
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Well, after some more testing it seems I spoke too soon. For whatever reason its only forwarding the Skill value but not the Attribute value.&nbsp; const attributes = ['Intellect', 'Cunning', 'Resolve', 'Might', 'Dexterity', 'Stamina', 'Presence', 'Manipulation', 'Composure']; on(`change:${attributes.join(' change:')} change:rollAttr sheet:opened`, function() {&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; getAttrs([...attributes, 'rollAttr'],function(values) {&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const attribute_name = values.rollattr;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const attribute_value = values[attribute_name]; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ active_attribute: values[attribute_value]] });&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; }); }); I tried making the attribute code look like a copy of the skill code but it still isn't working. :(
1565522855
GiGs
Pro
Sheet Author
API Scripter
anything in the change line needs to be in lower case. I forget to apply this earlier. Change that line to on(`change:${attributes.join(' change:').toLowerCase()} change:rollattr sheet:opened`, function() {&nbsp; &nbsp; For safety, add that .toLowerCase() in the same place for the earlier code. Funnily enough, your attribute_name line uses lower case, but that one should be the proper case. Assuming the attribute is rollAttr (I thought it was rollAttribute?) const attribute_name = values.rollAttr;&nbsp;