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

Radio button values --- 1 checked or 0 not

1542740422
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I want to use a set of radio buttons to send a value to a sheet worker. When checked 1 and unchecked 0. Is this possible? Each would have a different attr name but in the same group.
1542752718
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Savage Gamer, Is this for the purposes of creating a character sheet? If so, your post would get better notice and help in the Character Sheet forum. Let me know and I can move it for you.
1542753244
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Actually a little of both sheet worker and character sheet building.
1542754779
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Sheetworkers are a part of character sheet building. Can you clarify a little though? You mention radio buttons, but the behavior that you are describing sounds more like checkboxes. Either way, this is very easy to do: <input type="checkbox" name="attr_some_attribute" value="1"> The value here is the value of the checkbox when it is checked, not it's default value. This works similarly for radio buttons, except that then there are multiple options for a "checked" state: <input type="radio" name="attr_some_attribute" value="0" checked> <input type="radio" name="attr_some_attribute" value="1"> <input type="radio" name="attr_some_attribute" value="2"> <input type="radio" name="attr_some_attribute" value="3"> When using radio buttons, you need to designate one of the instances of the radio as the default value by adding the checked keyword to it. You can read more about checkboxes and radios at the linked pages.
1542755218
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Right I want them to behave like radio buttons but report like checkboxes. The sheet has three loadouts, a character can only carry one at a time. So it's either on or off "1 or 0" The encumbrance would be calculated against with that in the formula (loadout a * radio a) + (loadout b * radio b) and so on...
1542755975
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You can certainly use sheetworkers to set the others to 0, but I'd recommend using radio buttons for this. If you do want to continue with the checkbox method, this script should get you started: on('change:loadout1 change:loadout2 change:loadout3',(event)=>{     const resetter = {//A lookup of what to set based on which loadout was selected             loadout1:{loadout2:0,loadout3:0},             loadout2:{loadout1:0,loadout3:0},             loadout3:{loadout2:0,loadout1:0}         };     if(event.newValue*1===1){         setAttrs(resetter[event.sourceAttribute],{silent:true});     } });
1542757527

Edited 1542757797
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Ah, that's what I was trying to figure out. I knew I needed radio buttons, but I just couldn't connect them to the sheetworker like I wanted to. So it seems in this what is my current load would be the event? and source attribute is loadout weight??
1542757944
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Maybe a better way to do this is to st the loadouts as objects with their weight as part of the value? I'm still learning JS btw.