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

[Help] Select these three with a radio button

1456583406

Edited 1457107404
Coal Powered Puppet
Pro
Sheet Author
I am trying to get tricky with the math, and there isn't any caffeine in my house right now. I have an Armor section.  Each armor modifies three separate attributes (defense, armor, and speed).  I am trying to figure out how to set up a radio button so you can choose which armor you are wearing with a single click.  I have done this in the past, but only with a single attribute.  And I have done something similar with shape-shifting, but each attribute had its own series of radio buttons. Any one know how I am can make a single radio button tell the sheet to use three different values? 
1456584558
Finderski
Plus
Sheet Author
Compendium Curator
Coal Powered Puppet said: Any one know how I am can make a single radio button tell the sheet to use three different values?  Can you show us what the layout looks like? I'm struggling to comprehend the goal (possibly due to lack of caffeine as well). :)
1456586818

Edited 1456587114
I recommend SheetWorkers. This is super easy with SheetWorkers. However, as far as I know there is no way to combine that with repeating sections if you need this. You can use a button group inside of an repeating field but you can't have like a repeating section with a radio button to select which of the repeating items the character currently wears. If you need the latter you will have to use a checkbox instead of a radio button and manually iterate over all repeating items and uncheck the checkboxes and modify for example a hidden attribute set of current_armor, current_defense, current_speed. Edit: From your post again I guess you want to do exactly that, select the armor from a repeating section. I think this is impossible with radio buttons. You will have to use a checkbox and on the change event "unwear" all other armor and apply the triggering armor values to the current_ attributes. As event just use the radio button group change:armor_selected Then you can access the attribute armor_selected and make a choice what attributes to set. You would have something like if (armor == 'Heavy'){ setAttrs({ 'defense': -5, 'armor' : 10, 'speed' : 'slow' }); }else if (armor == 'Medium'){ setAttrs({ 'defense': -3, 'armor' : 5, 'speed' : 'medium' }); }else if (armor == 'Light'){ setAttrs({ 'defense': -1, 'armor' : 3, 'speed' : 'quick' }); }
Top Bar Armor section The checkbox looking thing is a radio button to pick if Flesh of Steel or the Worn armor is used.  I would like to add a few more worn armor slots. Wandler , I am not interested in repeating fields for this.  While the code you listed work (when adjusted for this game system)?
1456608231
Finderski
Plus
Sheet Author
Compendium Curator
Yeah, looking at this I'm with Wandler on this...you'll be better off using a Sheet Worker for this.
Okay...how?  The wiki is rather rough for me to understand. I get I lead off with  on("change:armor_arm_mod", function() { getAttrs(["worn_armor_arm", "worn_armor_def", "worn_armor_speed"], function(value) { But I have no clue what happens next.  Or even if this is the right way to do it. Say I have four 'protective gear' entries.  Each entry has Armor, Defense, and Speed modifiers, and a radio button next to it.  How do I structure the sheet work to change all three modifiers depending on which radio button is selected? 
1456634325
Lithl
Pro
Sheet Author
API Scripter
So your radio button is armor_arm_mod, and depending on the radio button chosen, you need to set different values to worn_armor_arm, worn_armor_def, and worn_armor_speed. Your sheet worker could look something like this: on('change:armor_arm_mod', function() { getAttrs(['armor_arm_mod'], function(values) { var attrs = {}, armor_arm_mod = parseInt(values.armor_arm_mod); switch (armor_arm_mod) { case 0: // Use appropriate values for the radio buttons attrs.worm_armor_arm = 0; // Use appropriate numbers for armor/defense/speed attrs.worn_armor_def = 5; attrs.worn_armor_speed = 2; break; case 1: attrs.worn_armor_arm = 1; attrs.worn_armor_def = 3; attrs.worn_armor_speed = 4; break; // Etc. for all radio button choices default: // Set values for armor/defense/speed if none of the radio buttons are selected break; } setAttrs(attrs); }); });
1456655338
Finderski
Plus
Sheet Author
Compendium Curator
Coal Powered Puppet said: Okay...how?  The wiki is rather rough for me to understand. You're not alone...the whole thing is confusing for me, too. When I was figuring out the Sheet Workers I had to rely heavily on Aaron and others (like Brian) to help me get it figured out. <not much help, I realize, but trying to offer some moral support :) >
Okay, installed the script, and naturally, its not working (because I touched it, I think).  Gonna fiddle with it some more and see what happens. Now, in Brian's script above, there is assigned number.  If I wanted the script to get attributes from, say @{armor_speed_mod-1}, how would I write the script? 
1456671292
Lithl
Pro
Sheet Author
API Scripter
Coal Powered Puppet said: Now, in Brian's script above, there is assigned number.  If I wanted the script to get attributes from, say @{armor_speed_mod-1}, how would I write the script?  Change the line: getAttrs(['armor_arm_mod'], function(values) { to: getAttrs(['armor_arm_mod', 'armor_speed_mod-1'], function(values) { You can then access @{armor_speed_mod-1} as values['armor_speed_mod-1']
I think is asked the question wrong.  I am going to break this down, Barney still, so I know I am asking the right thing. This is my html: <h4>Worn Armor</h4> <div class="body"> <table style="width:820px"> <tr> <td></td> <td><h5>Armor</h5></td> <th><h5>Type</h5></th> <th><h5>SPD Modifier</h5></th> <th><h5>DEF Modifier</h5></th> <th><h5>ARM Modifier</h5></th> </tr> <tr> <th><input type="radio" class="sheet-use" name="attr_armor_select" value="1" checked/><span></span></th> <td><input type="text" class="sheet-input-center-aligned" name="attr_armor_name-1" value="" placeholder="Armor Name" /></td> <td><select name="attr_armor_type-1" class="sheet-input-center-aligned sheet-select" style="width:120px"> <option value="None">None</option> <option value="Light">Light</option> <option value="Medium">Medium</option> <option value="Heavy">Heavy</option> </select></td> <th><input type="number" class="sheet-input-center-aligned" name="attr_armor_speed_mod-1" value="0" /></th> <th><input type="number" class="sheet-input-center-aligned" name="attr_armor_def_mod-1" value="0" /></th> <th><input type="number" class="sheet-input-center-aligned" name="attr_armor_arm_mod-1" value="0" /></th> </tr> <tr> <th><input type="radio" class="sheet-use" name="attr_armor_select" value="2" /><span></span></th> <td><input type="text" class="sheet-input-center-aligned" name="attr_armor_name-2" value="" placeholder="Armor Name" /></td> <td><select name="attr_armor_type-2" class="sheet-input-center-aligned sheet-select" style="width:120px"> <option value="None">None</option> <option value="Light">Light</option> <option value="Medium">Medium</option> <option value="Heavy">Heavy</option> </select></td> <th><input type="number" class="sheet-input-center-aligned" name="attr_armor_speed_mod-2" value="0" /></th> <th><input type="number" class="sheet-input-center-aligned" name="attr_armor_def_mod-2" value="0" /></th> <th><input type="number" class="sheet-input-center-aligned" name="attr_armor_arm_mod-2" value="0" /></th> </tr> </table> What I want is when the radio button is checked, the sheet worker applies @{armor_speed_mod-1}, @{armor_def_mod-1}, and @{armor_def_mod-1}, or the @{armor_speed_mod-2},  @{armor_def_mod-2}, and @{armor_def_mod-2} attributes to the @{worn_armor_speed}, @{worn_armor_def} and @{worn_armor_arm} attributes, respectively.   So, if I hit the radio button next to Armor-1, then Armor-1's speed, defense and armor modifiers are applied.  When I hit the radio button next to Armor-2, the next set of armor modifiers are applied.
Okay, by going back to Brian's example a dozen or so times, realizing each time I forgot something he had in the example, and lots of tweaks, I got it to work.  So, my next update to the Iron Kingdoms sheet will have multiple armors through the power of sheet workers! Side note: the sheet worker did not like the "-" symbols, so I used "_" instead.  Dunno why, but there you go.
1456715486
Finderski
Plus
Sheet Author
Compendium Curator
Congrats, CPP. Sheet Workers are both frustrating and awesome. :)
1456743145
Lithl
Pro
Sheet Author
API Scripter
Coal Powered Puppet said: Side note: the sheet worker did not like the "-" symbols, so I used "_" instead.  Dunno why, but there you go. Because - is not a valid character for a property literal in JavaScript. You can get around the restriction with array-like addressing, though. values.armor_speed_mod-1 : bad values['armor_speed_mod-1'] : good
Thank you very much for all your help with this Brian, and GV. Yawl are great. 
1456751726
Finderski
Plus
Sheet Author
Compendium Curator
Coal Powered Puppet said: Thank you very much for all your help with this Brian, and GV. Yawl are great.  LOL - all I did was cheer. Brian did ALLLL the heavy lifting. :)
Can't give Brian all the credit.  He might develop and ego and have self-respect and all that.  Can't let programmers getting self-respect.  
1456800658

Edited 1456800689
Lithl
Pro
Sheet Author
API Scripter
Coal Powered Puppet said: Can't give Brian all the credit.  He might develop and ego and have self-respect and all that.  Can't let programmers getting self-respect.   Now I know what Jabberjaw feels like. =P
1456806980
Finderski
Plus
Sheet Author
Compendium Curator
Brian said: Coal Powered Puppet said: Can't give Brian all the credit.  He might develop and ego and have self-respect and all that.  Can't let programmers getting self-respect.   Now I know what Jabberjaw feels like. =P LOL—you may have just dated yourself, Brian...I'm not sure how many people nowadays remember Jabberjaw.
1456825938
vÍnce
Pro
Sheet Author
+1