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

[rolltemplate] sending two values from select field

1623231631
Divers
Pro
Sheet Author
I would like to send two "values" from a "select" field to my rolltemplate. Basically I have a repeating fieldset, where the player can add new skills (to each skill there is a competence and its value associated). Into this repeating fieldset, each row is a select "field" which selects a competence as option (agility, force...). There is a button "type=roll" associated to it. I currently send the value of the selected competence, and I want to send the name of the selected competence as well. Following a stackoverflow post (<a href="https://stackoverflow.com/questions/3245967/can-an-option-in-a-select-tag-carry-multiple-values" rel="nofollow">https://stackoverflow.com/questions/3245967/can-an-option-in-a-select-tag-carry-multiple-values</a>), I tried : &lt; option value = '{"attr_competenceValue":@{agility},"attr_competenceName":"Agility"}' &gt;Agility &lt;/ option &gt; And then send @{competenceValue} and @{competenceName} to the rolltemplate. But this doesn't work &gt; I tried as well a &lt;script&gt; to update the attributes, but as the select field is part of a fieldset repeating, i can not update the attribute by its name or id...
1623234378

Edited 1623241371
GiGs
Pro
Sheet Author
API Scripter
The fact it's a repeating section shouldnt make a difference here, since you dont need to use any repeating section properties to get values, if the button is on the same row as the attributes. The option value syntax you are using there doesnt look valid for roll20. It looks like a JSON string, which is overcomplicated for what you're doing. A better way to do this in roll20, is have your select choose the attribute name, and a sheet worker set a hidden attribute's value to the relevant value. So you'd have something like &lt; h4 &gt; Agility:&nbsp; &lt;/ h4 &gt; &lt; input &nbsp; type = "number" &nbsp; name = "attr_agility" &nbsp; value = "0" &gt; &lt; h4 &gt; Force:&nbsp; &lt;/ h4 &gt; &lt; input &nbsp; type = "number" &nbsp; name = "attr_force" &nbsp; value = "0" &gt; &lt; h4 &gt; Mind:&nbsp; &lt;/ h4 &gt; &lt; input &nbsp; type = "number" &nbsp; name = "attr_mind" &nbsp; value = "0" &gt; &lt; fieldset &nbsp; class = "repeating_competence" &gt; &nbsp;&nbsp; &lt; select &nbsp; name = "attr_competence_name" &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option &nbsp; &gt; Agility &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option &nbsp; &gt; Force &lt;/ option &gt; &nbsp;&nbsp;&nbsp;&nbsp; &lt; option &nbsp; &gt; Mind &lt;/ option &gt; &nbsp;&nbsp; &lt;/ select &gt; &nbsp;&nbsp; &lt; input &nbsp; type = "hidden" &nbsp; name = "attr_competence_value" &nbsp; value = "0" &nbsp; &gt; &nbsp;&nbsp; &lt; button &nbsp; type = "roll" &nbsp; value = "Name: @{competence_name}; Value: @{competence_value}" &gt;&lt;/ button &gt; &lt;/ fieldset &gt; &lt; script &nbsp; type = "text/worker" &gt; &nbsp;&nbsp;const&nbsp;competence_section&nbsp;=&nbsp;'repeating_competence'; &nbsp;&nbsp;const&nbsp;stats&nbsp;=&nbsp;['agility',&nbsp;'force',&nbsp;'mind']; &nbsp;&nbsp;const&nbsp;changeStats&nbsp;=&nbsp;stats.reduce((str,&nbsp;stat)&nbsp;=&gt;&nbsp;`&nbsp;${str}&nbsp;change:${stat}`,&nbsp;'sheet:opened'); &nbsp;&nbsp;on(`change:${competence_section}:competence_name&nbsp;${changeStats}`,&nbsp;(event)&nbsp;=&gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;getSectionIDs(competence_section,&nbsp;idarray&nbsp;=&gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;fieldnames&nbsp;=&nbsp;[]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;idarray.forEach(id&nbsp;=&gt;&nbsp;fieldnames.push( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`${competence_section}_${id}_competence_name`, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`${competence_section}_${id}_competence_value` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getAttrs([...stats,&nbsp;...fieldnames],&nbsp;values&nbsp;=&gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;output&nbsp;=&nbsp;{}; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;idarray.forEach(id&nbsp;=&gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;stat&nbsp;=&nbsp;values[`${competence_section}_${id}_competence_name`]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output[`${competence_section}_${id}_competence_value`]&nbsp;=&nbsp;values[stat.toLowerCase()]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs(output); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;}); To adapt to your needs you only have to edit two lines: &nbsp;&nbsp;const&nbsp;competence_section&nbsp;=&nbsp;'repeating_competence'; &nbsp;&nbsp;const&nbsp;stats&nbsp;=&nbsp;['agility',&nbsp;'force',&nbsp;'mind']; These two lines - just enter the name of your repeating section here, and enter your stat names here. You dont need to change any of the rest of the sheet worker. To use this, see the post belowyou'll obviously need to search and replace every instance of repeating_compentence with your repeating section Also be careful about the case of attribute names. Use lower case for your attribute names, or the above wont work. use compenentce_name and competence_value, instead of CompetenceName and CompetenceValue.
1623235939
Divers
Pro
Sheet Author
Wow thanks for this extended answer !! I'll give it a try right now.
1623237416

Edited 1623237498
GiGs
Pro
Sheet Author
API Scripter
I just removed some unneccesary code I had in there for testing (roll20's behaviour has changed in a recent update, and it I wasnt ware of it). Also i had a typo in one attribute name.
1623238973
GiGs
Pro
Sheet Author
API Scripter
I also just realised I had an oversight in my earlier code of the sheet worker, so I've fixed that, and made it easier for you to adapt to your needs. The problem: if you change a stat outside the repeating section, like agility or force, it doesnt get updated within the repeating section The updated code is more complex, but fixes that. Secondly, to adapt to your needs you only have to edit two lines: &nbsp;&nbsp;const&nbsp;competence_section&nbsp;=&nbsp;'repeating_competence'; &nbsp;&nbsp;const&nbsp;stats&nbsp;=&nbsp;['agility',&nbsp;'force',&nbsp;'mind']; These two lines - just enter the name of your repeating section here, and enter your stat names here. You dont need to change any of the rest of the sheet worker.
1623240914
Divers
Pro
Sheet Author
Thanks again ! That works. I manage to make it work with your first post. I will improve it with your last posts ;-)
1623241138

Edited 1623241289
Divers
Pro
Sheet Author
On more question : how to update this when I change my competence value (character's agility improves from 3 to 4) ??? As I coded it, the attributes update when I change the selected competence. (as expected by the code line: on(`change:${competence_section}:competence_name&nbsp;${changeStats}`,&nbsp;(event)&nbsp;=&gt; ) This is usefull as in the system we are playing, the competence values vary more often than the competence which is selected in the fieldset.
1623241613
GiGs
Pro
Sheet Author
API Scripter
If I understand correctly, the code already should do that for you - thats the reason for the last edit. This part ${changeStats} on the change line watches all the attribute values outside the repeating section, and when any of them changes, updates the repeating section with the correct value. As long as the array near the start has the full list of attributes it will work. That's this bit: &nbsp;&nbsp;const&nbsp;stats&nbsp;=&nbsp;['agility',&nbsp;'force',&nbsp;'mind']; Expand that to include all your attributes. If you had a charisma attribute, you'd change that to &nbsp;&nbsp;const&nbsp;stats&nbsp;=&nbsp;['agility',&nbsp;'force',&nbsp;'mind', 'charisma'];
1623241744
Divers
Pro
Sheet Author
Awesome !! You make my character sheet far better than previously, and improve my skills ! Thanks again :-)
1623242096
GiGs
Pro
Sheet Author
API Scripter
Youre welcome :)