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

Change button roll depending on select

1625319379

Edited 1625319416
.Hell
Sheet Author
Hello, I want to change some content of a button role, depending on a previous selected item. The problem I am running into is, that I need two values. <div class='sheet-melee-options'> <select name="attr_activeweapon"> <option value="">primary</option> <option value="secondary">secondary</option> <option value="third">third</option> <option value="fourth">fourth</option> <option value="fifth">fifth</option> <option value="sixth">shield</option> </select> <button type='roll' data-i18n="fast-strikes-u" class='sheet-skill-roller2' value= '@{whisper}&{template:statistics3} {{title=MELEE-Test}} {{name=@{character_name}}}{{roll=[[1d10!+@{ref}[STAT]+@{melee_total}[SKILL]?{EXTRA ACTION|No,+0|Yes,-3}[EXTRA ACTION]+0[FAST STRIKES]+?{WEAPON SELECTION|@{primary_weapon_name},@{primary_wa}|@{secondary_weapon_name},@{secondary_wa}|@{third_weapon_name},@{third_wa}|@{fourth_weapon_name},@{fourth_wa}|@{fifth_weapon_name},@{fifth_wa}|@{sixth_weapon_name},@{sixth_wa}|Shield, 0}[WEAP. ACC]?{1ST ATTACK LOCATION|Random,+0|Head,-6|Torso,-1|Arm/Limb,-3|Leg/Tail/Wing,-2}[LOCATION]+?{1ST ATTACK MODS? (Bright Light, No Vision, Terrain etc)|0}[MOD]]]}}{{roll1weapon=primary}} {{roll2=[[1d10!+@{ref}[STAT]+@{melee_total}[SKILL]?{EXTRA ACTION|No,+0|Yes,-3}[EXTRA ACTION]+0[FAST STRIKES]+?{WEAPON SELECTION|@{primary_weapon_name},@{primary_wa}|@{secondary_weapon_name},@{secondary_wa}|@{third_weapon_name},@{third_wa}|@{fourth_weapon_name},@{fourth_wa}|@{fifth_weapon_name},@{fifth_wa}|@{sixth_weapon_name},@{sixth_wa}|Shield, 0}[WEAP. ACC]?{2ND ATTACK LOCATION|Random,+0|Head,-6|Torso,-1|Arm/Limb,-3|Leg/Tail/Wing,-2}[LOCATION]+?{2ND ATTACK MODS? (Bright Light, No Vision, Terrain etc)|0}[MOD]]]}}'>FAST STRIKES</button> I need the weapon name and wa (weapon accuracy). Is it even possible to do it this way? I tried to do a some kind of nested call @{@{activeweapon}_wa} but that doesnt work. I appreciate any help :) P.S: a secondary question is if I can get the weapon name to show inside the option
1625323201

Edited 1625324142
GiGs
Pro
Sheet Author
API Scripter
Can you include more details, like what weapon names you want to display and use? You will likely need a sheet worker. Do this to set up the select and hidden input <select name="attr_activeweapon"> <option value="sword" selected>Sword</option> <option value="handaxe">Hand-Axe</option> <option value="hammer">Hammer</option> </select> <input type="hidden" name="activeweapon_wa" value="sword_wa"> You need to two attributes. First the select sets the weapon name - notice that the displayed name can be different from the option value. You want the option value to be a legal sheet worker name. Then you create a sheet worker, to create the hidden attribute something like this: on('change:activeweapon',eventInfo => {     setAttrs({         activeweapon_wa: `@{${eventInfo.newValue}_wa}`     }); }); This means whenever the select value is changed, the hidden attribute changes to the matching wa value. Then you can use @{activeweapon} and @{activeweapon_wa} in your macro to get the correct attributes. If you want @{activeweapon} to include a fancy name, like "Hand-Axe", you'd need to change the sheet worker to include some processing to convert the name to a valid attribute name. Do you need to do that? (Though maybe Hand-Axe_wa is valid? I cant remember.)
1625323389
GiGs
Pro
Sheet Author
API Scripter
Though looking at your button code, it seems like you have a separate query there to get the weapon name and wa. That bypasses the select. Which method are you actually using?
1625329377
.Hell
Sheet Author
Hey Gigs, I want to replace the query with the select. Most players have one weapon that they use and choosing it every time they press the button is quite cumbersome. For the additional details you ask: <select name="attr_activeweapon"> <option value="primary">@{primary_weapon_name}</option> </select> I wanted to do it like that
1625331960

Edited 1625332007
GiGs
Pro
Sheet Author
API Scripter
That wont work, it's not possible in roll20 for the contents of selects to be updated dynamically. You have to hardcode the specific items you want to show in each excel.
1625498117
.Hell
Sheet Author
To bad that the select cannot be done dynamically, but the solution with the sheet worker works well. Thanks