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

How do I use a checkbox to choose between two attributes

1512485092
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
So the situation is this. I have a called shot checkbox. When it is it is checked the value to be reported is @{hitlocationchoice} and when not checked the value reported should be @hitlocationroll I think there are two ways of doing this. One with a radio button that has another one hidden under it or with a sheetworker. Below is my poor attempt at a sheetworker for this issue. // Call Shot vs Random hit location Script on('change:calledshotcheck' function(e) { calledshotswitch(); }); // Update Hit Location function calledshotswitch() { console.log('*****Called Shot Switch******'); getAttrs(['calledshot_check','hitlocationroll', 'hitlocationchoice'], function(v) { var attrs = {}; if (v.calledshotcheck === "0") { hitlocation = "hitlocationroll"; } else if (v.calledshotcheck === "1") { hitlocation = "hitlocationchoice"; } setAttrs({ hitlocation: hitlocation, }); }); }
1512493680

Edited 1512493935
chris b.
Pro
Sheet Author
API Scripter
yeah you need a radio button. or if you use a checkbox, just use 1 or 0, then use a sheetworker to grab the checkbox and 2 other values each time or a checkbox and set a 2nd field like you are doing
1512493998

Edited 1512497413
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
OK so with the sheetworker how do I do that? Because what I came up with does not work.
1512496409

Edited 1512496581
I'm not the best with javascript but could you use the checkbox 1/0 value to do something like "@{hitlocationchoice}".repeat('checkboxvalue')+"@{hitlocationroll}".repeat(1-'checkboxvalue') But obviously with the right syntax for everything haha.
1512501039

Edited 1512501083
Lithl
Pro
Sheet Author
API Scripter
No need for any sheet workers at all in this case: [[@{hitlocationchoice} * @{calledshotcheck} + @{hitlocationroll} * (1 - @{calledshotcheck})]]
1512506323

Edited 1512507172
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
// Call Shot vs Random hit location Script on('change:calledshotcheck' function(e) { calledshotswitch(); }); // Update Hit Location function calledshotswitch() { console.log('*****Called Shot Switch******'); getAttrs(['calledshot_check','hitlocationroll', 'hitlocationchoice'], function(v) { var attrs = {}; if (v.calledshotcheck === "0") { hitlocation = "1t[HLT]"; } else if (v.calledshotcheck === "1") { hitlocation = "hitlocationchoice"; } setAttrs({ hitlocation: hitlocation, }); }); }
1512520443
chris b.
Pro
Sheet Author
API Scripter
You might have to use == instead of === for checking the checkboxes, i had to when using strings. otherwise have to use parseInt