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

want sheetworker check checkbox's value

1689622159

Edited 1689624773
Hello, I am editing a published doublecross 3rd sheet. ( <a href="https://github.com/Roll20/roll20-character-sheets/blob/master/DoubleCross3rd/DoubleCross3rd.html" rel="nofollow">https://github.com/Roll20/roll20-character-sheets/blob/master/DoubleCross3rd/DoubleCross3rd.html</a> ) This function is applied to this sheet, and through the value of the checkbox, I want to use this data when the value is 0, and load other data when the value is 1. and I made checkbox like this &lt;div class="sheet-reduction-section"&gt; &lt;div class="sheet-tit" data-i18n="i_reduction"&gt;침식치&lt;/div&gt; &lt;div class="sheet-form"&gt; &lt;input type="text" name="attr_reduction" value="0" placeholder="0"/&gt; &lt;span&gt;/&lt;/span&gt; &lt;input type="text" name="attr_reduction_max" value="300" class="sheet-max"/&gt; &lt;input type="hidden" name="attr_hide_reduction" value="" /&gt; &lt;/div&gt; &lt;div&gt; &lt;input type="hidden" name="attr_reduction_per" class="sheet-graph-per" value="" /&gt; &lt;div class="sheet-graph-box"&gt; &lt;div class="sheet-bar"&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="sheet-ohter"&gt; &lt;strong data-i18n="i_reduction_03" style="background: #fff; color: #000"&gt;기원종&lt;/strong&gt; &lt;input type="checkbox" name="attr_reduction_03" value="1"/&gt; &lt;/div&gt; &lt;div class="sheet-ohter"&gt; &lt;strong data-i18n="i_add_dice"&gt;추가 주사위&lt;/strong&gt; &lt;input type="number" name="attr_add_dice" value="0" placeholder="0"/&gt; &lt;/div&gt; &lt;div class="sheet-ohter"&gt; &lt;strong data-i18n="i_add_effect_level"&gt;추가 레벨&lt;/strong&gt; &lt;input type="number" name="attr_effect_level" value="0" placeholder="0"/&gt; &lt;/div&gt; &lt;/div&gt; In this case, should we use the on change function to check the value of the checkbox? function getreduction_effect(type) { var data = {0:0,1:0}; // 1 - add dice / 2 - add level if(type &gt;= 60) { // reduction more than 60 data[0] = 1; } if(type &gt;= 80) { // reduction more than 80 data[0] = 2; } if(type &gt;= 100) { // reduction more than 100 data[0] = 3; data[1] = 1; } if(type &gt;= 130) { // reduction more than 130 data[0] = 4; } if(type &gt;= 160) { // reduction more than 160 data[1] = 2; } if(type &gt;= 190) { // reduction more than 190 data[0] = 5; } if(type &gt;= 220) { // reduction more than 220 data[1] = 3; } if(type &gt;= 260) { // reduction more than 260 data[0] = 6; } if(type &gt;= 300) { // reduction more than 300 data[0] = 7; } return data; }
1689626279

Edited 1689626295
GiGs
Pro
Sheet Author
API Scripter
It's hard to tell exacly what you want to happen from the function (generally soeaking, I think a global function is a bad idea in Roll20, unless its going to be used by multiple sheet workers). Assuming this is the checkbox you are using: &lt;input type="checkbox" name="attr_reduction_03" value="1"/&gt; You would need a sheet worker that looks like: on ( 'change:reduction_03' , function () { &nbsp; &nbsp; getAttrs ([ 'reduction_03' ], function ( values ) { &nbsp; &nbsp; &nbsp; &nbsp; // you might need to add more attributes to getAttrs - I don't know what you're doing. &nbsp; &nbsp; &nbsp; &nbsp; const reduction = + values . reduction_03 || 0 ; &nbsp; &nbsp; &nbsp; &nbsp; const output = {}; // create an object to hold the values you intend to send to setAttrs &nbsp; &nbsp; &nbsp; &nbsp; if ( reduction ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // whatever you want to calculate when reduction == 1 &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // what happens on 0 &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ( output ); &nbsp; &nbsp; }); }); If you just want to know how to set the on('change') part up, that would look like on ( 'change:reduction_03' , function () { &nbsp; &nbsp; }); You'd need at least the getAttrs line though to grab its value, and the value of any other attributes whose value you want to use.
1689628465

Edited 1689629433
thank you for your thinking!&nbsp;I've never learned to code, so it's hard to explain.&nbsp; I'm so sorry. TT I don't know if the translator will explain it well, but I'll try it once. I think this part is probably related to the function I posted at the beginning. and I think of the first function var data = {0:0,1:0}; // 1 - add dice / 2 - add level I think the part specifies the value of the dice and level that are added that way. This is to set the number of buff dice that are automatically added when the numberexceeds a certain number. Taking an item increases the number of buff dice you receive for the same reduction value. (I would like to implement this as a checkbox check.) I think I can modify it with the code I just explained in this part. How about it? Thank you so much every time. It's really helpful. on("change:reduction change:reduction_max change:base_reduction change:modify_reduction", function() { getAttrs(["reduction", "reduction_max", "base_reduction"], function(values) { // 최종 침식치 var b_reduction = values.reduction * 1; var t_reduction = b_reduction; setAttrs({reduction:t_reduction}); var chk_reduction = t_reduction &gt; values.reduction_max ? values.reduction_max : t_reduction; setAttrs({hide_reduction:chk_reduction}); // 침식치 별 수정 효과 (이펙트 레벨 및 최종 다이스 효과) // -- 이펙트 다이스 효과는 콤보에서만 설정하도록 한다. var red_effect = getreduction_effect(t_reduction); var add_dice = red_effect[0]; // 판정 다이스 업 var add_lv = red_effect[1]; // 이펙트 레벨업 // 1) data [1] setAttrs({effect_level:add_lv}); // 2) data [0] setAttrs({add_dice:add_dice}); let max = values.reduction_max; let now = values.reduction; let pers = (now == 0 || max == 0) ? 0 : now/max*100; pers = Math.floor(pers); setAttrs({reduction_per: pers}); }); }); GiGs said: It's hard to tell exacly what you want to happen from the function (generally soeaking, I think a global function is a bad idea in Roll20, unless its going to be used by multiple sheet workers). Assuming this is the checkbox you are using: &lt;input type="checkbox" name="attr_reduction_03" value="1"/&gt; You would need a sheet worker that looks like: on ( 'change:reduction_03' , function () { &nbsp; &nbsp; getAttrs ([ 'reduction_03' ], function ( values ) { &nbsp; &nbsp; &nbsp; &nbsp; // you might need to add more attributes to getAttrs - I don't know what you're doing. &nbsp; &nbsp; &nbsp; &nbsp; const reduction = + values . reduction_03 || 0 ; &nbsp; &nbsp; &nbsp; &nbsp; const output = {}; // create an object to hold the values you intend to send to setAttrs &nbsp; &nbsp; &nbsp; &nbsp; if ( reduction ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // whatever you want to calculate when reduction == 1 &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // what happens on 0 &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ( output ); &nbsp; &nbsp; }); }); If you just want to know how to set the on('change') part up, that would look like on ( 'change:reduction_03' , function () { &nbsp; &nbsp; }); You'd need at least the getAttrs line though to grab its value, and the value of any other attributes whose value you want to use.
1689631728
GiGs
Pro
Sheet Author
API Scripter
You say This is to set the number of buff dice that are automatically added when the numberexceeds a certain number. My question is: added to what?
1689658232

Edited 1689658264
buff dice list is like this! second image is when I check in checkbox. GiGs said: You say This is to set the number of buff dice that are automatically added when the numberexceeds a certain number. My question is: added to what?
1689680221
GiGs
Pro
Sheet Author
API Scripter
I need the roll20 attribute names affected.
1689682281

Edited 1689682367
GiGs said: I need the roll20 attribute names affected. reduction is attr_reduction add dice is&nbsp; attr_add_dice add level is&nbsp; attr_effect_level
1689689208
GiGs
Pro
Sheet Author
API Scripter
I just noticed an issue in the last code you posted: on("change:reduction change:reduction_max change:base_reduction change:modify_reduction", function() { getAttrs(["reduction", "reduction_max", "base_reduction"], function(values) { // 최종 침식치 var b_reduction = values.reduction * 1; var t_reduction = b_reduction; setAttrs({reduction:t_reduction}); var chk_reduction = t_reduction &gt; values.reduction_max ? values.reduction_max : t_reduction; setAttrs({hide_reduction:chk_reduction}); // 침식치 별 수정 효과 (이펙트 레벨 및 최종 다이스 효과) // -- 이펙트 다이스 효과는 콤보에서만 설정하도록 한다. var red_effect = getreduction_effect(t_reduction); var add_dice = red_effect[0]; // 판정 다이스 업 var add_lv = red_effect[1]; // 이펙트 레벨업 // 1) data [1] setAttrs({effect_level:add_lv}); // 2) data [0] setAttrs({add_dice:add_dice}); let max = values.reduction_max; let now = values.reduction; let pers = (now == 0 || max == 0) ? 0 : now/max*100; pers = Math.floor(pers); setAttrs({reduction_per: pers}); }); }); This code will work, but it is slow. You want to have only one setAttrs in each sheet worker. You can create a Javascript Object to hold all the final values. This is a better worker: on ( "change:reduction change:reduction_max change:base_reduction change:modify_reduction" , function () { &nbsp; &nbsp; getAttrs ([ "reduction" , "reduction_max" , "base_reduction" ], function ( values ) { &nbsp; &nbsp; &nbsp; &nbsp; const output = {}; &nbsp; &nbsp; &nbsp; &nbsp; // 최종 침식치 &nbsp; &nbsp; &nbsp; &nbsp; var b_reduction = values . reduction * 1 ; &nbsp; &nbsp; &nbsp; &nbsp; var t_reduction = b_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; output . reduction = t_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; var chk_reduction = t_reduction &gt; values . reduction_max ? values . reduction_max : t_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; output . hide_reduction = chk_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 침식치 별 수정 효과 (이펙트 레벨 및 최종 다이스 효과) &nbsp; &nbsp; &nbsp; &nbsp; // -- 이펙트 다이스 효과는 콤보에서만 설정하도록 한다. &nbsp; &nbsp; &nbsp; &nbsp; var red_effect = getreduction_effect ( t_reduction ); &nbsp; &nbsp; &nbsp; &nbsp; var add_dice = red_effect [ 0 ]; // 판정 다이스 업 &nbsp; &nbsp; &nbsp; &nbsp; var add_lv = red_effect [ 1 ]; // 이펙트 레벨업 &nbsp; &nbsp; &nbsp; &nbsp; // 1) data [1] &nbsp; &nbsp; &nbsp; &nbsp; output . effect_level = add_lv ; &nbsp; &nbsp; &nbsp; &nbsp; // 2) data [0] &nbsp; &nbsp; &nbsp; &nbsp; output . add_dice = add_dice ; &nbsp; &nbsp; &nbsp; &nbsp; let max = values . reduction_max ; &nbsp; &nbsp; &nbsp; &nbsp; let now = values . reduction ; &nbsp; &nbsp; &nbsp; &nbsp; let pers = ( now == 0 || max == 0 ) ? 0 : now / max * 100 ; &nbsp; &nbsp; &nbsp; &nbsp; pers = Math . floor ( pers ); &nbsp; &nbsp; &nbsp; &nbsp; output . reduction_per = pers ; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ( output ); &nbsp; &nbsp; }); });
1689694954

Edited 1689701637
The code you changed works fine. cool! Then, including what you told me at the beginning, I added data like this and changed the function. function getreduction_effect2(type) { var data = {0:0,1:0}; // 1 - 다이스 / 2 - 이펙트 레벨 if(type &gt;= 60) { // 침식치 60 이상 data[1] = 0; } if(type &gt;= 80) { // 침식치 80 이상 data[1] = 1; } if(type &gt;= 100) { // 침식치 100 이상 data[1] = 2; } if(type &gt;= 150) { // 침식치 160 이상 data[1] = 3; } if(type &gt;= 200) { // 침식치 190 이상 data[1] = 4; } return data; } and&nbsp; on("change:reduction change:reduction_max change:base_reduction change:modify_reduction change:reduction_03", function() { getAttrs(["reduction", "reduction_max", "base_reduction"], function(values) { const reduction = +values.reduction_03 || 0; const output = {}; if(reduction) { // 최종 침식치 var b_reduction = values.reduction * 1; var t_reduction = b_reduction; output.reduction = t_reduction; var chk_reduction = t_reduction &gt; values.reduction_max ? values.reduction_max : t_reduction; output.hide_reduction = chk_reduction; // 침식치 별 수정 효과 (이펙트 레벨 및 최종 다이스 효과) // -- 이펙트 다이스 효과는 콤보에서만 설정하도록 한다. var red_effect = getreduction_effect2(t_reduction); var add_dice = red_effect[0]; // 판정 다이스 업 var add_lv = red_effect[1]; // 이펙트 레벨업 // 1) data [1] output.effect_level = add_lv; // 2) data [0] output.add_dice = add_dice; } else { var b_reduction = values.reduction * 1; var t_reduction = b_reduction; output.reduction = t_reduction; var chk_reduction = t_reduction &gt; values.reduction_max ? values.reduction_max : t_reduction; output.hide_reduction = chk_reduction; // 침식치 별 수정 효과 (이펙트 레벨 및 최종 다이스 효과) // -- 이펙트 다이스 효과는 콤보에서만 설정하도록 한다. var red_effect = getreduction_effect(t_reduction); var add_dice = red_effect[0]; // 판정 다이스 업 var add_lv = red_effect[1]; // 이펙트 레벨업 // 1) data [1] output.effect_level = add_lv; // 2) data [0] output.add_dice = add_dice; } let max = values.reduction_max; let now = values.reduction; let pers = (now == 0 || max == 0) ? 0 : now/max*100; pers = Math.floor(pers); output.reduction_per = pers; setAttrs(output); }); }); Like this? GiGs said: I just noticed an issue in the last code you posted: on("change:reduction change:reduction_max change:base_reduction change:modify_reduction", function() { getAttrs(["reduction", "reduction_max", "base_reduction"], function(values) { // 최종 침식치 var b_reduction = values.reduction * 1; var t_reduction = b_reduction; setAttrs({reduction:t_reduction}); var chk_reduction = t_reduction &gt; values.reduction_max ? values.reduction_max : t_reduction; setAttrs({hide_reduction:chk_reduction}); // 침식치 별 수정 효과 (이펙트 레벨 및 최종 다이스 효과) // -- 이펙트 다이스 효과는 콤보에서만 설정하도록 한다. var red_effect = getreduction_effect(t_reduction); var add_dice = red_effect[0]; // 판정 다이스 업 var add_lv = red_effect[1]; // 이펙트 레벨업 // 1) data [1] setAttrs({effect_level:add_lv}); // 2) data [0] setAttrs({add_dice:add_dice}); let max = values.reduction_max; let now = values.reduction; let pers = (now == 0 || max == 0) ? 0 : now/max*100; pers = Math.floor(pers); setAttrs({reduction_per: pers}); }); }); This code will work, but it is slow. You want to have only one setAttrs in each sheet worker. You can create a Javascript Object to hold all the final values. This is a better worker: on ( "change:reduction change:reduction_max change:base_reduction change:modify_reduction" , function () { &nbsp; &nbsp; getAttrs ([ "reduction" , "reduction_max" , "base_reduction" ], function ( values ) { &nbsp; &nbsp; &nbsp; &nbsp; const output = {}; &nbsp; &nbsp; &nbsp; &nbsp; // 최종 침식치 &nbsp; &nbsp; &nbsp; &nbsp; var b_reduction = values . reduction * 1 ; &nbsp; &nbsp; &nbsp; &nbsp; var t_reduction = b_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; output . reduction = t_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; var chk_reduction = t_reduction &gt; values . reduction_max ? values . reduction_max : t_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; output . hide_reduction = chk_reduction ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 침식치 별 수정 효과 (이펙트 레벨 및 최종 다이스 효과) &nbsp; &nbsp; &nbsp; &nbsp; // -- 이펙트 다이스 효과는 콤보에서만 설정하도록 한다. &nbsp; &nbsp; &nbsp; &nbsp; var red_effect = getreduction_effect ( t_reduction ); &nbsp; &nbsp; &nbsp; &nbsp; var add_dice = red_effect [ 0 ]; // 판정 다이스 업 &nbsp; &nbsp; &nbsp; &nbsp; var add_lv = red_effect [ 1 ]; // 이펙트 레벨업 &nbsp; &nbsp; &nbsp; &nbsp; // 1) data [1] &nbsp; &nbsp; &nbsp; &nbsp; output . effect_level = add_lv ; &nbsp; &nbsp; &nbsp; &nbsp; // 2) data [0] &nbsp; &nbsp; &nbsp; &nbsp; output . add_dice = add_dice ; &nbsp; &nbsp; &nbsp; &nbsp; let max = values . reduction_max ; &nbsp; &nbsp; &nbsp; &nbsp; let now = values . reduction ; &nbsp; &nbsp; &nbsp; &nbsp; let pers = ( now == 0 || max == 0 ) ? 0 : now / max * 100 ; &nbsp; &nbsp; &nbsp; &nbsp; pers = Math . floor ( pers ); &nbsp; &nbsp; &nbsp; &nbsp; output . reduction_per = pers ; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ( output ); &nbsp; &nbsp; }); }); I tested it and it worked! thank you.&nbsp;