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

A little help please with checkbox and script writer

At the moment i'm using a checkbox to select the class that would be shown. is there a way to write it so that when the selected script writer activates, it auto selects the relevent checkbox (radio or similar ) to show the right Class Thanks.. 11 different Classes..  each with totally different layouts. just showing 2 atm..  as an example CSS etc. .sheet-TINKERER:not(:checked) ~ .sheet-tinkerer, .sheet-ROGUE:not(:checked) ~ .sheet-rogue {     display: none; } HTML etc. <input type="checkbox" class="sheet-ROGUE"><span>ROGUE |</span> <input type="checkbox" class="sheet-TINKERER"><span>TINKERER |</span> <div class="rogue"> </div> <div class="tinkerer"> </div> <script...  etc.         else if (setting.pcs === 'e10') {              setAttrs({classes: 'TINKERER',                 Mana: '3',                 Health: '5',                 name: 'Keylee',                 htp1: 'http',         Ability: 'COMBAT: discared 1 Item: gain +2 dice rerolls.',                 Shadow: '+1 Mob Item from your current level.'});         }         else if (setting.pcs === 'a11') {              setAttrs({classes: 'ROGUE',                 Mana: '3',                 Health: '4',                 name: 'Valerie',                 htp1: 'http',         Ability: 'In Shadow ATTACK: -2 Shields.',                 Shadow: 'Kill 1 minion. +1 Rogue token: Discard it or save it till the next draw.'});         }
1672525231
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I would recommend specifying a check value for your checkboxes (I tend to use 1  as my check value since the unchecked value is always 0 ). Beyond that, I'm not entirely sure what your question is. It looks to me like you have this set up so that you would click the checkbox and then the script would fire to setup the dependent attributes. Something that would help is if you could share your whole function in question rather than just part of it. One piece that I would critique is having multiple setAttrs, each behind an if. Instead, simply create an empty object and then store the changes you want to make in that, then call setAttrs with that object as the first argument at the very end. This lets you dynamically assign values and more easily troubleshoot issues.
1672528796
GiGs
Pro
Sheet Author
API Scripter
I mirror everything Scott says (and even as I was reading your post I was thinking - "hmm that checkbox needs a value") It's hard to dagnose without seeing your full sheet worker. What is going on there, what is (setting.pcs === 'e10'), and how does that tie into the checkbox and hidden/visible sections.
1672530061

Edited 1672532790
Oosh
Sheet Author
API Scripter
If I'm understanding rightly you're essentially describing tabs . Put a hidden input before your Class divs (as in Rogue/Tinkerer Class) with a suitable name: <input class="class-display-toggle" type="hidden" name="attr_display_class" /> <div class="class-display rogue" /> <div class="class-display tinkerer" /> Then set your CSS like: .class-display { display: none; } .class-display-toggle[value="rogue"] ~ .class-display.rogue, .class-display-toggle[value="tinkerer"] ~ .class-display.tinkerer { display: block; } Then all you need to do is add the display_class attribute to the object you feed into setAttrs (which I would set up the way Scott described) and assign it the right value. I'm not sure if that's what you mean? You can have that hooked up to a <select> drop-down or something - it's probably easier than a checkbox (and attribute) for every Class in your game. Oh... add all the sheet- prefixes as required if you're using Legacy. Which.... if there's no particular reason you're using legacy I'd definitely move to CSE. edit - this is probably a more helpful example... same CSS as above but otherwise functional: <div> <select name="attr_class"> <option value="">-</option> <option value="rogue">Rogue</option> <option value="tinkerer">Tinkerer</option> </select> <div class="class-container"> <input class="class-display-toggle" type="hidden" name="attr_class" /> <div class="class-display rogue"> <p>Rogue display</p> <p>Health: <span name="attr_health" /></p> <p>Mana: <span name="attr_mana" /></p> </div> <div class="class-display tinkerer"> <p>Tinkerer display</p> <p>Health: <span name="attr_health" /></p> <p>Mana: <span name="attr_mana" /></p> </div> </div> </div> <script type="text/worker"> on('change:class', ({ newValue }) => { if (newValue === '-') return; const attributeOutput = {}; if (newValue === 'rogue') { Object.assign(attributeOutput, { mana: '4', health: '5', }); } else if (newValue === 'tinkerer') { Object.assign(attributeOutput, { mana: '3', health: '5', }); } setAttrs(attributeOutput); }); </script> Anything that's common to all classes you probably want outside the class display to reduce the amount of duplicate HTML. For example, presumably all classes have Health - so move it outside the conditional display. But maybe some classes have another resource like Rage instead of Mana? It's a nice touch to hide the irrelevant stats rather than set them to 0. Again... might not be what you were asking for.
Thanks for your input guys..&nbsp;&nbsp; I only know how to code Roll20, by asking a pro, or looking at another html and working out how it works.. so its not perfect or text book.... also&nbsp; describing my problem or expaining it might be causing confusion.. &lt;select name="attr_pcs" &lt;option value="0"&gt; -- ROGUE -- &lt;/option&gt; &lt;option value="f11"&gt;Feydra&lt;/option&gt; &lt;option value="c11"&gt;Mist&lt;/option&gt; &lt;option value="b11"&gt;Sicarius&lt;/option&gt; &lt;option value="e11"&gt;Silence&lt;/option&gt; &lt;option value="a11"&gt;Valerie&lt;/option&gt; &lt;option value="d11"&gt;Whisper&lt;/option&gt; &lt;option value="0"&gt; -- TINKERER -- &lt;/option&gt; &lt;option value="c10"&gt;Daisy&lt;/option&gt; &lt;option value="d10"&gt;Jebediah&lt;/option&gt; &lt;option value="e10"&gt;Keylee&lt;/option&gt; &lt;option value="b10"&gt;Siegfried&lt;/option&gt; &lt;option value="a10"&gt;Zoe&lt;/option&gt; &lt;script else if (setting.pcs === 'd10') { setAttrs({classes: 'TINKERER', Mana: '4', Health: '4', name: 'Jebadiah', htp: 'http', Ability: '+2 MP during your first Move action each round.', Shadow: 'You may return 1 discarded Item to your Inventory.'}); } else if (setting.pcs === 'e10') { setAttrs({classes: 'TINKERER', Mana: '3', Health: '5', name: 'Keylee', htp: 'http', Ability: 'COMBAT: discared 1 Item: gain +2 dice rerolls.', Shadow: '+1 Mob Item from your current level.'}); } else if (setting.pcs === 'a11') { setAttrs({classes: 'ROGUE', Mana: '3', Health: '4', name: 'Valerie', htp: 'http', Ability: 'In Shadow ATTACK: -2 Shields.', Shadow: 'Kill 1 minion. +1 Rogue token: Discard it or save it till the next draw.'}); } else if (setting.pcs === 'b11') { setAttrs({classes: 'ROGUE', Mana: '3', Health: '4', name: 'Sicarius', htp: 'http', Ability: 'If no other Hero is in Line of Sight: ATTACK: +2 Swords.', Shadow: 'Return any number of discarded Rogue tokens: +1 dice reroll / returned token.'}); } with the script writer.. the attrs&nbsp; Mana, Health, Ability and Shadow.. are not the problem.. they are used elsewhere.. my question was about using the attr 'classes' to trigger the checkboxes ... &lt;input type="checkbox" class="sheet-ROGUE"&gt;&lt;span&gt;ROGUE&amp;nbsp;|&lt;/span&gt; &lt;input type="checkbox" class="sheet-TINKERER"&gt;&lt;span&gt;TINKERER&amp;nbsp;|&lt;/span&gt; there are 11 different classes&nbsp; and it is 'tabs'&nbsp; i was trying to have the PCs selection trigger the right checkbox through the scriptwriter.. instead of manually clicking on the relevant checkbox. i haven't put much code into the Classes area yet..&nbsp; thats soon.. and gonna be very difficult for some classes.. heres a&nbsp; link to the game .. so you can look at the sheet.. <a href="https://app.roll20.net/join/14230534/Zn_QnA" rel="nofollow">https://app.roll20.net/join/14230534/Zn_QnA</a>
1672672831

Edited 1672672873
GiGs
Pro
Sheet Author
API Scripter
Rick I. said: also&nbsp; describing my problem or expaining it might be causing confusion.. Try describing the problem again. Pretend you haven't said anything it all, and describe the issue from basics. Also, it would be better to link the sheet's actual code, not a place to join the game. (Though that won't help with a clear description of the problem.) The code you've pasted has the same issues as code you posted earlier - you don't describe how its used, or include the start of your sheet worker. That said, I notice an issue in the select html. &lt;option value="0"&gt; -- ROGUE -- &lt;/option&gt; &lt;option value="f11"&gt;Feydra&lt;/option&gt; &lt;option value="c11"&gt;Mist&lt;/option&gt; &lt;option value="b11"&gt;Sicarius&lt;/option&gt; &lt;option value="e11"&gt;Silence&lt;/option&gt; &lt;option value="a11"&gt;Valerie&lt;/option&gt; &lt;option value="d11"&gt;Whisper&lt;/option&gt; &lt;option value="0"&gt; -- TINKERER -- &lt;/option&gt; Rogue and Tinkerer both have a value of 0. If one of them is selected, the sheet will always drop back to the first one when reopened. Select options need unique values. That's probably not your issue, but I thought it woth mentioning.
the &lt;option value="0" &gt; -- TINKERER-- &lt;/option&gt; is a&nbsp; Header..&nbsp; never selected ..&nbsp; because &lt;optgroup label=" -- TINKERER -- "&gt; will not work 'Legacy Sanitation' !
1672694090
GiGs
Pro
Sheet Author
API Scripter
Your reply is puzzling - there's no optgroup text in the example. If you want something to be present but never selected in the dropdown, you can set it disabled, like so &lt;option disabled &gt; -- TINKERER -- &lt;/option&gt; You don't need to give it a value since it'll never be selected. As far as i understand what you're asking, Oosh's post above describes a solution. Check that again and see if it solves your problem. If not, try again to describe what your problem is.
didn't know you could wite it that way!