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 .
×

Technical question on HTML selection values.

Is it possible to have a single selection option have multiple values you can use in different parts of a roll template?  < select name = "attr_WoundLevel" > < option value = "0" selected = "selected" > Healthy < /option > < option value = "1" > Stunned < /option > < option value = "1" > Wounded < /option > < option value = "2" > Wounded Twice < /option > < option value = "5" > Incapacitated < /option > < option value = "10" > Mortally Wounded < /option >   < /select > So if I wanted to use the last selection option to show in a template the value 10 in one section but wnated the template to show Mortally Wounded in another part of the template. How do I achieve this? Thanks  
1668423446

Edited 1668484659
Oosh
Sheet Author
API Scripter
An option element can only have a single value - if you want to use multiple values you'll need to either encode them into the value and split them later, or use a sheetworker to update a second attribute. Something like this: // html <select name="attr_woundlevel"> <option value="0" selected>Healthy</option> <option value="0.5">Stunned</option> <option value="1">Wounded</option> <option value="2">Wounded Twice</option> <option value="5">Incapacitated</option> <option value="10">Mortally Wounded</option> </select> <input type="hidden" name="attr_woundlevel_display" /> // js const woundMap = { '0': 'Healthy', '0.5': 'Stunned', '1': 'Wounded', '2': 'Wounded Twice', '5': 'Incapacitated', '10': 'Mortally Wounded' }; const setWoundLevelDisplay = () => { getAttrs(['woundlevel'], (attributeValues) => { const woundLevelDisplay = woundMap[attributeValues.woundlevel] || 'Unknown'; setAttrs({ woundlevel_display: woundLevelDisplay }); }); } on('change:woundlevel', setWoundLevelDisplay); I changed the value for Stunned, since you'd used '1' twice. And it's best to avoid capital letters in attribute names - snake case is the preference there. So WoundLevel would be either woundlevel or wound_level depending on your preference. From there you'd just use @{woundlevel} and @{woundlevel_display} in your roll template depending on whether you want the number or the text.
Thanks!
If I didn't want to use the sheet worker, you mentioned splitting the value after. What would that look like?
1668485119
Oosh
Sheet Author
API Scripter
That would be using Custom Roll Parsing to pull the value apart to insert into the roll - it's more involved from a Javascript point of view, and probably only a good idea if you prefer writing Javascript to HTML & Roll20 chat syntax. To decode the value at roll time would likely also mean using Promises to combine Roll20's getAttrs function with your roll function - possibly not something you'd be keen on doing. It does have the benefit of keeping your character sheet fairly lean, and you could get fancy and use base64 encoding or something to insert a massive heap of information into a single attribute, but it does require some reasonably advanced JS to use dynamically at roll time. TLDR - the one above is the simpler solution
1668485853

Edited 1668488668
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Oosh said: That would be using Custom Roll Parsing to pull the value apart to insert into the roll - it's more involved from a Javascript point of view, and probably only a good idea if you prefer writing Javascript to HTML & Roll20 chat syntax. To decode the value at roll time would likely also mean using Promises to combine Roll20's getAttrs function with your roll function - possibly not something you'd be keen on doing. I would point out that this option is not actually possible as promises (except when used directly on a startRoll call) break character sheets. You can do it by getting all possible attribute values before you run the crp function (ala what the K-scaffold does). Sheetworkers to update another attribute with the appropriate values or to do the CRP manipulation is frankly your best option assuming that you need to use the select value for an actual calculation as well.
Thanks for the advice!