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

[Help] Using select to calculate various dependent values

1443949775
Sönke
Sheet Author
Hi, I am new to character sheet development and have been looking for a way to exactly determine which value was chosen in a select so that I can use this information to calculate other dependent values. I could not find anything in the help or in the forums, but I might have missed something. So I came up with my own solution which works, but seems rather cumbersome: <select name="attr_Species"> <option value="3">Human</option> <option value="5">Elf</option> <option value="7">Halfelf</option> <option value="11">Dwarf</option> </select> <input style="display:none;" name="attr_species_human" type="number" disabled="true" value="1-ceil((@{Spezies}%3)/100)"/> <input style="display:none;" name="attr_species_elf" type="number" disabled="true" value="1-ceil((@{Spezies}%5)/100)"/> <input style="display:none;" name="attr_species_halfelf" type="number" disabled="true" value="1-ceil((@{Spezies}%7)/100)"/> <input style="display:none;" name="attr_species_dwarf" type="number" disabled="true" value="1-ceil((@{Spezies}%11)/100)"/> Now I can so stuff like the following: <input type="number" disabled="true" name="attr_SK_base_value" value=" -5*(@{species_human})-4*(@{species_elf})-4*(@{species_halfelf})-4*(@{species_dwarf})" /> <input type="number" disabled="true" name="attr_ZK_base_value" value="-5*(@{species_human})-6*(@{species_elf})-6*(@{species_halfelf})-4*(@{species_dwarf})" /> So, my question is: Is there any easier / more natural way to do achieve this? It is fine for 4 species, but I do have cases with a lot longer selects and a way to simplify the process would be greatly appreciated. Thank you and best regards Sönke
1444180745
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I am afraid that you are most probably on the correct track.  As it happens, I was just looking around in here hoping that I could find something better than what I had come up with for the exact same problem, but I don't think there is anything much better than your or my code. Mine looks like the following. <option value="2" title="Movement Rate 14, Karma Modifier 4, Low Light Vision."> Elf</option> <input type="number" name="attr_Race-Elf"        value="(1-(((abs(@{Race}- 2 )+1)-abs(abs(@{Race}- 2 )-1))/2))" disabled /> <input type="number" name="attr_Race-Human" value="(1-(((abs(@{Race}- 3 )+1)-abs(abs(@{Race}- 3 )-1))/2))" disabled /> My formula is based off of         1-min(abs(@{Race}-(whatever)),1)     which will return 1 where @{Race} == (whatever) and zero otherwise. With the Min formula being (((@{x} + @{y}) - abs(@{x} - @{y})) / 2) as has been posted in this forum many times before. The one advantage I see in using the min() formulation rather than your code is that you don't have to assign the values to prime numbers, you can just number them 1 through whatever. You have to replace both the -3's in the code above with the option number you are testing for.  But anyway, no, I don't think there is any easier or more intuitive way of doing this.