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

How to transfer a variable from a

I have an attr in as a value in an <input> that I want to use to select a value from an array within a <script> then export the result from the array back to a value in the character sheet.  but I have no clue how to do that, any help would be appreciated. <input type="text" name="attr_exp_weapon9_tot" value="(@{exp_weapon9_1} + @{exp_weapon9_2} + @{exp_weapon9_3} + @{exp_weapon9_4} + @{exp_weapon9_5})" disabled="true" style="width: 45px;" /> <script type="text/worker"> const WeaponArray1 = [4,4,5,6,6,7,8,8,9,10,10,11,12,12,13,14,14,15,16,16,18,20,20,20,20,20,20,20]; let ToHit1 = WeaponArray1[weapon9_tot]; </script> <input type="text" value="(@{ToHit1})">
I kind of see what you are doing.  You might consider 2 different paths.   1. Use ScriptCards and program your logic within it.   2. Write it as a JavaScript API Function. I would say to use a RollTable, but you don’t appear to have any randomness in your logic. -Will M.
1681184843
GiGs
Pro
Sheet Author
API Scripter
You cant mix autocalcs with sheet workers (at least, not without a lot of specific effort). If your select and input are both normal attributes (not disabled=true), then changing one will change the other to match. If you change the input to a value that isn't in the select options, it will become unselected. If you want to use the input to select a value from the select, a good option is a datalist (you can't be using legacy HTML code, though - datalists don't work). With that option, clicking in the input will give you a list that matches the select, and players can pick from it.
1681184988
GiGs
Pro
Sheet Author
API Scripter
I see I focussed on the word select a bit too much, I shouldn't answer when still waking up or going to bed. But the point about disabled attributes is still good - your inpt is disabled, so you won't be able to use that with your sheet worker code. If you want people to pick from a slist of options in your array, the way to go would probably to change your input to a select with those options listed, or to change to a datalist (not disabled) to again present the list on need.
Thank you for the replies. So, to explain a little further, I am trying to automate some of the fields in the character sheet.  this specific section is related to the combat system.  Each weapon has what is called an Expertise value, the field specified in the <input> attr_exp_weapon9_tot is the total from all of the specific aspects that, combined, set that expertise. The base chance to hit is determined by the expertise (which can be seen in the WeaponArray1)  I am trying to figure out how to set the Base To Hit value on the character sheet from the Expertise Total. The random die roll is added to the To Hit total. So if there is a way to pull a value from an array based on another variables value, thats what I need.   As a note, I don't expect any values to exceed 25 (after 2 years of play we are at an expertise level of 17...)
1681190465

Edited 1681190502
GiGs
Pro
Sheet Author
API Scripter
Without knowing the specifics of every detail, I can't really give a more specific answer. To be clear: I'm talking about the specifics about how the roll is made at the table if you weren't using roll20, not the programming.
Hi Gigs  there is no roll leading up to the "To Hit" calculation, its all just entered values that create the Exp_Weapon9_tot value ummmmm here so the Expertise is calculated by adding the weapon combat style base (which is usually 10) + a Characteristic Modifier + an experience bonus + a Training bonus = Expertise based on the Expertise total we then look at this chart in the Game Book: Expertise Base to Hit 3-4 4 5 5 6-7 6 8 7 9-10 8 11 9 12-13 10 14 11 15-16 12 17 13 18-19 14 20 15 21-22 16 23 18 24+ 20 Then to calculate the actual To Hit value you add a weapon Modifier which creates value that you need to then roll a d20 against if the roll is less than the To Hit Total you "HIT" your target I am trying to figure out how to take the Expertise Total and calculate the base To Hit value.  At this time we are manually updating the To Hit value when characters gain experience and their Expertise goes up.
1681192582

Edited 1681192640
GiGs
Pro
Sheet Author
API Scripter
The expertise value is calculated as: If score < 23, 2 + 2/3 x Expertise, rounded down If score 23: 18, score 24+ 20. This isn't hard to include in a sheet worker. It might be harder in an autocalc. I'd probably have a hidden expertise_mod input, that is updated whenever expertise changes. The use expertise_mod in your attack bonus calculation.