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

How do I add custom weapons to say a dropdown list?

Basically I've got a Fieldset that's a repeating inventory type deal. I want to be able to take the names of the items my players put into the text box and have it automatically added to a list depending on what type of item they check off. Example being like, they add a weapon named "Longsword" they check the weapon box, and then on another page they can select "Longsword" as their weapon. I'm 99.9% sure I need to use a sheetworker but they are WAY over my head. It took 2 days to get the repeatingsum sheetworker working for me, so I'd appreciate any help/advice. This is the code for the repeating inventory thing:     <fieldset class="repeating_inventory" name="attr_inventory">         <table class="sheet-center" style="width:100%">             <tr>                 <td>Item</td>                 <td><input type="text" class="sheet-number" name="attr_item_name" /></td>                 <td>Weight</td>                 <td><input type="number" class="sheet-number" name="attr_item_weight" /></td>                 <td>Amount</td>                 <td><input type="number" class="sheet-number" name="attr_item_amount" /></td>             </tr>             <tr>                 <td colspan="6"><textarea name="attr_item_text" style="width:97%" ></textarea></td>             </tr>             <tr>                 <td>Armor   <input type="checkbox" name="attr_armor_equip" /></td>                 <td colspan="1">Weapon   <input type="checkbox" name="attr_weapon_select" value="weapon"/></td>         </table>         <br>     </fieldset> And this is the code for the weapon selection thing:                 <tr>                     <td><button type='roll' class="sheet-skill_button" name="attr_weapon_roll-left" value='&{template:attack} {{rollname=@{weapon_name-left}}} {{attack=[[@{weapon_select-left}]]}} {{damage=[[(@{weapon_number_dice-left}@{weapon_damage_die-left}) + @{weapon_damage_bonus-left}]]}} {{dmgtype=@{weapon_type-left}}}'></button></td>                     <td colspan="3"><select class="sheet-select" name="attr_weapon_name-left" />                         <option></option>                         <option></option>                         <option></option>                         <option></option>                     </td>                </tr>
1602105616

Edited 1602105627
GiGs
Pro
Sheet Author
API Scripter
There's no way to do dynamic dropdowns on roll20 character sheets. All dropdowns must be completely defined during the design stage - their contents cannot be edited in use.
Balls, well thank you.
1602106283
GiGs
Pro
Sheet Author
API Scripter
Yeah, I imagine on the wish lists of sheet authors, that feature would be very high for everyone.
1602108506
Tetrakern
Sheet Author
Compendium Curator
I only experimented with it in my head, but since you can add repeating rows per sheetworker, you could probably fake a drop down list by bastardizing the repeating list. Analyze the input from your inventory, put it into the corresponding repeating list, and force it with CSS to look like a dropdown or something that serves the same purpose. The first element could be the equipped weapon and you would collapse/expand it to select one by sorting, the add button would be hidden. Or you could use a button/checkbox as trigger to sort the list with a sheetworker. I got no proof of concept, but it seems viable to me albeit not trivial.
1602108759
GiGs
Pro
Sheet Author
API Scripter
If you can show a proof of concept, I'd love to see it.
1602180909
Tetrakern
Sheet Author
Compendium Curator
Urg. But only because I brought this upon myself... IT IS PROVEN! (This is by no means ready to be used for anything. Also, I went for the fastest option.) HTML (COMPLIED FROM PUG) <div>Accessor Attribute @{right_weapon}</div> <input type="text" name="attr_right_weapon"/> <h4>Right Weapon</h4> <div class="sheet-equipment-list"> <input class="sheet-toggle" type="checkbox" name="attr_item_equip_toggle"/> <fieldset class="repeating_rightweapon"> <div class="sheet-repitem"> <label> <input type="checkbox" name="attr_item_equip_toggle"/><span>Equip</span> </label> <input type="text" name="attr_item_name"/> </div> </fieldset> </div> <h4>Inventory</h4> <div class="sheet-equipment-list"> <fieldset class="repeating_inventory"> <div class="sheet-repitem"> <label> <input type="radio" name="attr_item_type" value="weapon"/><span>W</span> </label> <label> <input type="radio" name="attr_item_type" value="armor"/><span>A</span> </label> <label> <input type="radio" name="attr_item_type" value="misc"/><span>M</span> </label> <input type="text" name="attr_item_name"/> </div> </fieldset> </div> SCRIPT on('change:repeating_inventory:item_type', (e) => { if (e.newValue == 'weapon') { let name = e.sourceAttribute.replace('_type', '_name'), newId = generateRowID(); getAttrs([name], (value) => { let target = "repeating_rightweapon_" + newId + "_item_name"; setAttrs({ [target]: value[name] }); }); } }); on('change:repeating_rightweapon:item_equip_toggle', (e) => { let name = e.sourceAttribute.replace('_equip_toggle', '_name'); getAttrs([name], (value) => { setAttrs({ ['right_weapon']: value[name] }); }); }); CSS (COMPILED FROM SCSS) *, ::before, ::after { box-sizing: border-box; } h4 { margin: 40px 0 2px; } .sheet-toggle { appearance: none; position: absolute; top: -19px; right: 0; border: 0; outline: none; } .sheet-toggle::after { content: '&'; display: flex; align-items: center; justify-content: center; font-family: Pictos; font-size: 12px; line-height: 1; height: 16px; width: 16px; outline: none; } .sheet-toggle:focus { outline: none; } .sheet-toggle:checked::after { content: '_'; } .sheet-toggle:not(:checked) ~ .repcontainer { display: none; } .sheet-equipment-list { position: relative; border-top: 1px solid #666666; padding-top: 4px; width: 300px; } .sheet-equipment-list * { font-size: 10px; line-height: 1; } .sheet-equipment-list .repcontainer { margin-bottom: 16px; } .sheet-equipment-list .repitem { margin-bottom: 2px; } .sheet-equipment-list .sheet-repitem { display: flex; background-color: #f3f3f3; padding: 4px; border-radius: 2px; } .sheet-equipment-list .sheet-repitem label { cursor: pointer; display: block; padding: 0; margin: 0 4px 0 0; width: auto; } .sheet-equipment-list .sheet-repitem label span { display: flex; align-items: center; justify-content: center; border-radius: 2px; height: 16px; } .sheet-equipment-list .sheet-repitem label input[type=radio] { display: none; } .sheet-equipment-list .sheet-repitem label input[type=radio] + span { background-color: #ffffff; border: 1px solid #cccccc; width: 16px; } .sheet-equipment-list .sheet-repitem label input[type=radio]:checked + span { background-color: #666666; color: #ffffff; border-color: #666666; } .sheet-equipment-list .sheet-repitem label input[type=checkbox] { display: none; } .sheet-equipment-list .sheet-repitem label input[type=checkbox] + span { background-color: #444444; color: #ffffff; padding: 0 4px; } .sheet-equipment-list .sheet-repitem input[type=text] { display: block; flex-grow: 1; font-size: 10px; line-height: 16px; padding: 0 2px; border: 1px solid #ccc; border-radius: 2px; height: 16px; width: auto; outline: none; }
1602187026
GiGs
Pro
Sheet Author
API Scripter
Thats a clever way to simulate it, using the repeating section copy trick. It's not really a dropdown, since it doesnt float above the page, though you could probably get a better simulation by adding it on a div that does hover above the page.
1602190142
Tetrakern
Sheet Author
Compendium Curator
GiGs said: Thats a clever way to simulate it, using the repeating section copy trick. It's not really a dropdown, since it doesnt float above the page, though you could probably get a better simulation by adding it on a div that does hover above the page. ... You can make it exactly like a dropdown with CSS, I just couldn't bother. It's the same principle as demonstrated here , which can be applied to the repcontainer that holds all items anyway. Just add "position: absolute" and "relative" to the parent, plus positioning and space reservation. This can also be done without hover, albeit that's more tricky. There are various tutorials on the Internet how to do this.
I'm super impressed man, well done!