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

Custom Character Sheet: Help with checkbox

1707119778

Edited 1707119876
So I've set up a checkbox with some custom css, I got it looking exactly how I want, and have the checked value returning how I want the issue is the unchecked value is returning 0. Is there a sheet worker that can check is its 0 and return something else? Or another way to do this? I want unchecked to be d6!6>4 (exploding dice) and the checked to be  d6>4 (not  exploding dice) The project I'm working on you can get a condition called "hindered" that makes your dice not explode. So I just want a toggle that can turn on and off the exploding element.
1707125710

Edited 1707636243
vÍnce
Pro
Sheet Author
checkboxes return 0 when unchecked and the value you assign when checked.  So it's easier to just use 0 and 1 to actually trigger the "good stuff" to happen. You should be able to do something like; <script type="text/worker"> on('change:hindered_checkbox', (eventInfo) => { getAttrs(['hindered_checkbox'], (v) => { const output = {}; const hinderedState = parseInt(v.hindered_checkbox) || 0;       output.hindered = hinderedState === 1 ? 'd6!6>4' : 'd6>4'; setAttrs(output, {silent: true}); }); }); </script> * EDIT/UPDATE: fixed the ternary operator as per info further down in the thread. This assumes a checkbox of "attr_hindered_checkbox" with "attr_hindered" as the attribute you want to hold the dice roll.  Just adjust the names to match your code. I believe you could also accomplish this without a worker using a couple radio buttons as well, but you would have to redo your cool checkbox. ;-) Cheers
1707126817
Stephen C.
Pro
Sheet Author
I would place a hidden input on the sheet which holds the default value, and then the sheetworker could change it like Vince said.
1707134518
GiGs
Pro
Sheet Author
API Scripter
And Vince says he's not very good with sheet workers... Though I think that hindered line might have the state reversed. Should it be: output.hindered = hinderedState === 1 ? 'd6!6>4' : 'd6>4'; You could also write this is output.hindered = hinderedState ? 'd6!6>4' : 'd6>4'; since in Javascript, "any actual value" and "no value" are two separate states (truthy and falsy), and JS if statements check for truthy and falsy values.
1707134864

Edited 1707141134
GiGs
Pro
Sheet Author
API Scripter
Personally, I'd just put the "!" in the logical test. So you have your button macro which has a value like value="/roll 1d6@{hindered}>4" (or maybe you put that roll in a rolltemplate) Then the hidden attribute suggested by Stephen, and the checkbox suggested by Vince. <input type="hidden" name="attr_hidden" value=""> <inout type="checkbox" name="attr_hindered_checkbox" value="1"> That is the checkbox in your image. And the sheet worker as suggested by Vince with a small change <script type="text/worker"> on('change:hindered_checkbox sheet:opened', (eventInfo) => { getAttrs(['hindered_checkbox'], (v) => { const output = {}; const hinderedState = parseInt(v.hindered_checkbox) || 0; output.hindered = hinderedState ? '!6' : ''; setAttrs(output, {silent: true}); }); }); </script> Sometimes getting things working in character sheets is convoluted! Note: the sheet:opened part of the worker is orobably necessary here. You need that to ensure the attribute is created. Otherwise the checkbox needs to be clicked once to run the sheet worker.
1707143485
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
GiGs said: Note: the sheet:opened part of the worker is orobably necessary here. You need that to ensure the attribute is created. Otherwise the checkbox needs to be clicked once to run the sheet worker. I'd argue it isn't. Just set the hidden attribute's default value to whatever the state should be the first time a sheet is opened. I'd also say this is a perfect place to use Custom Roll Parsing (CRP). Then you don't even need the hidden attribute, you just have your crp function figure out what roll to use at roll time. <button type="action" name="act_roll">Roll according to hindered</button> and then your CRP roll function looks like: on('clicked:roll',()=>{ // note the async tag on our callback function for getAttrs. This is going to let us wait for the roll. getAttrs(['hindered_checkbox'],async (attributes)=>{ const hindered = +attributes.hindered_checkbox || 0; const hinderText = hindered ? '!6' : ''; const inlineRoll = `[[1d6${hinderText}>4]]`; // Send the roll to the chat parser and wait for the result const roll = await startRoll(`&{template:default} {{roll=${inlineRoll}}}`); // We could do some post processing on this, but we don't need to for this setup, so we just finalize the roll immediately finishRoll(roll.rollId); }) });
1707149467
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: GiGs said: Note: the sheet:opened part of the worker is orobably necessary here. You need that to ensure the attribute is created. Otherwise the checkbox needs to be clicked once to run the sheet worker. I'd argue it isn't. Just set the hidden attribute's default value to whatever the state should be the first time a sheet is opened. I tried that, but it only worked properly on first load once I added sheet:opened. I thought the default value would work, but it doesn't seem to.
1707163154

Edited 1707163246
GiGs said: Personally, I'd just put the "!" in the logical test. So you have your button macro which has a value like value="/roll 1d6@{hindered}>4" (or maybe you put that roll in a rolltemplate) Then the hidden attribute suggested by Stephen, and the checkbox suggested by Vince. <input type="hidden" name="attr_hidden" value=""> <inout type="checkbox" name="attr_hindered_checkbox" value="1"> That is the checkbox in your image. And the sheet worker as suggested by Vince with a small change <script type="text/worker"> on('change:hindered_checkbox sheet:opened', (eventInfo) => { getAttrs(['hindered_checkbox'], (v) => { const output = {}; const hinderedState = parseInt(v.hindered_checkbox) || 0; output.hindered = hinderedState ? '!6' : ''; setAttrs(output, {silent: true}); }); }); </script> Sometimes getting things working in character sheets is convoluted! Note: the sheet:opened part of the worker is orobably necessary here. You need that to ensure the attribute is created. Otherwise the checkbox needs to be clicked once to run the sheet worker. THANK YOU! This worked great! (It was backwards, but easily fixed by swapping the css to be reversed and just setting it to checked: true so it starts "checked" - but visually is unchecked.)
1707169585
vÍnce
Pro
Sheet Author
SeaGoatGames said: THANK YOU! This worked great! (It was backwards, but easily fixed by swapping the css to be reversed and just setting it to checked: true so it starts "checked" - but visually is unchecked.) I knew that was what you really wanted to do. lol ;-P
1707185222

Edited 1707185343
  Separate question, how do I get rid of the line above the buttons? I've run the code that is supposed to clear the style and set the css to have no outline or border, but the line remains? I just want text only buttons with no background or outline, and I've gotten nearly there but the weird line. Oddly enough its gone when being pressed. Below I've put my css code. .ui-dialog .charsheet button[type=roll]::before {     content:""; } .charsheet button[type=roll].sheet-def_btn {     border: none;     color: white;     background-image:none;     font-size: 40px;     background-color: rgba(0,0,0,0.0);     font-family: 'Paytone One', sans-serif;     height: 40px;     width: 40px;     border-style: none;     border-radius: 0px;     border: none;     outline: none; }
1707188925
GiGs
Pro
Sheet Author
API Scripter
You have to figure out where the line is coming from. Are the buttons inside another object like a div. They may be coming from that border. They aren't standaerd colours for roll20, so those lines are being assigned in your CSS. Findig errant CSS can often be very tricky. You can start by assigning borders and colours to your button, and see if they are lined up perfectly with those lines. If not, its definitely coming from another element. By the way, you have border: none twice in that CSS declaration.
1707190357
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Based on the spacing, I would look at the css for your inputs (or whatever those numbers are.
The numbers are the buttons.
I added a border-radius to the css for the buttons and it shaped to them. So I don't think its from another div.
1707194516
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, looking at it, it's likely a box-shadow (or drop-shadow)
Thank you! That worked!