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

Attributes in character sheet NOT updating

1725644231

Edited 1725645002
(I'm a Korean speaker. However the code itself is written in English.) If I change the attribute that name 'base_reduction', it should work the same way with 'attr_reduction_per'. But sometimes the 'attr_reduction_per' doesn't respond to certain numbers. There are so many numbers that don't respond that it's hard to write(e.g. 80). The code(HTML) is here I guess... This is my first time to use Github. If you need some translations, please let me know. Thanks.
1725647581
GiGs
Pro
Sheet Author
API Scripter
Can you post the names of some attributes that don't work, and describe how they are being changed. Also you should try to avoid having more than one setAttrs in the same worker. You have: on("change:hp change:hp_mod change:hp_total", function() {         getAttrs(["hp", "hp_max", "hp_total", "hp_mod"], function(values) {             let mod = values.hp_mod;             let total = values.hp_total;             let max = (total*1) + (mod*1);             let now = values.hp;             let pers = (now == 0 || max == 0) ? 0 : now/max*100;             pers = Math.floor(pers);             setAttrs({hp_per: pers});             setAttrs({hp_max: max});         });     }); Theree are two setAttrs functions there, so you could rewrite this as: on("change:hp change:hp_mod change:hp_total", function() {         getAttrs(["hp", "hp_max", "hp_total", "hp_mod"], function(values) {             let output = {};             let mod = values.hp_mod;             let total = values.hp_total;             let max = (total*1) + (mod*1);             let now = values.hp;             let pers = (now == 0 || max == 0) ? 0 : now/max*100;             pers = Math.floor(pers);             output.hp_per = pers;             output.hp_max =  maxl             setAttrs(output);         });     }); Create an output variable (name it whatever you want); this is a javascript object - save your final attribute values to it, then use a single setAttrs to update all your attributes at nce. This is a lot more effecient, and leads to less lag, than doing them separately. Also, I don't know the original stats but wherever you have something like             let mod = values.hp_mod; I'd consider changing that to             let mod = values.hp_mod || 0; If it's in a longer line, put the hole thing in brackets, like (values.hp_mod || 0) Do this whenever the attribute is supposed to be a number. The || 0 means "OR 0" so if it is a string, it'll be converted to the number 0. This avoids workers crashing from certain errors (mainly - but not exclusively - to do with addition).
1725648909

Edited 1725648972
Actually this isn't my code. I'm just using it after modifying it to my preference(for personal use). The problem is here: We only use base_reduction (Attribute). It means we can only change  base_reduction  directly(in Roll20 character sheet). And since  base_reduction  changes, t his part below(attr_reduction_per?) should be changed as base_reduction value.                 <div> <input type="hidden" name="attr_reduction_per" class="sheet-graph-per" value="" /> <div class="sheet-graph-box"> <div class="sheet-bar"><span></span></div> </div> </div> JS code is here, I can't find any other reduction changing js code :( sorry: on("change:reduction change:reduction_max change:base_reduction change:add_reduction", function() { getAttrs(["reduction", "reduction_max", "base_reduction", "add_reduction"], function(values) { // Final reduction var b_reduction = values.base_reduction * 1; var t_reduction = b_reduction + (values.add_reduction *1); setAttrs({reduction:t_reduction}); var chk_reduction = t_reduction > values.reduction_max ? values.reduction_max : t_reduction; setAttrs({hide_reduction:chk_reduction}); // Bonus by reduction value var red_effect = getreduction_effect(t_reduction); var add_dice = red_effect[0]; // plus dice var add_lv = red_effect[1]; // plus level // 1) Additional level setAttrs({effect_level:add_lv}); // 2) Additional dice 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}); }); }); +) Here is 03:55 AM so maybe I'm gonna sleep. Good night (in advance)!
1725652656
GiGs
Pro
Sheet Author
API Scripter
I suggest trying to make the changes I suggested to that worker. It's possible it isn't probably being converted amd operated on. That would look like this: on("change:reduction change:reduction_max change:base_reduction change:add_reduction", function() { getAttrs(["reduction", "reduction_max", "base_reduction", "add_reduction"], function(values) { let output = {}; // Final reduction var b_reduction = values.base_reduction || 0; var t_reduction = b_reduction + (values.add_reduction || 0);                         output.reduction = t_reduction; var chk_reduction = t_reduction > (values.reduction_max || 0) ? (values.reduction_max || 0) : t_reduction; output. hide_reduction = chk_reduction; // Bonus by reduction value var red_effect = getreduction_effect(t_reduction); // what is this function? var add_dice = red_effect[0]; // plus dice var add_lv = red_effect[1]; // plus level // 1) Additional level output. effect_level = add_lv; // 2) Additional dice output. add_dice:add_dice; let max = values.reduction_max || 0; let now =  t_reduction ; let pers = (now == 0 || max == 0) ? 0 : now/max*100; pers = Math.floor(pers); output. reduction_per = pers;                         setAttrs(output); }); }); There's something I'd want to check here: this line calls a function var red_effect = getreduction_effect(t_reduction); You'd need to include that, so we can check it is working properly. Luckily you included the address of the code earlier. That is function getreduction_effect(type) {         var data = {0:0,1:0}; // 1 - 다이스 / 2 - 이펙트 레벨         if(type >= 60) { // 침식치 60 이상             data[0] = 1;         }         if(type >= 80) { // 침식치 80 이상             data[0] = 2;         }         if(type >= 100) { // 침식치 100 이상             data[0] = 3;             data[1] = 1;         }         if(type >= 130) { // 침식치 130 이상             data[0] = 4;         }         if(type >= 160) { // 침식치 160 이상             data[1] = 2;         }         if(type >= 190) { // 침식치 190 이상             data[0] = 5;         }         if(type >= 220) { // 침식치 220 이상             data[1] = 3;         }         if(type >= 260) { // 침식치 260 이상             data[0] = 6;         }         if(type >= 300) { // 침식치 300 이상             data[0] = 7;         }         return data;     } I cant tell if this is working properly, but it looks like that the first line creates a data variable, but the later lines are based on a different format. This create an initial variable: var data = {0:0,1:0}, this means data[0] = 0:0, and data[1] = 1:0, but the if statements later set a simple integer, 1, 2, 3, etc. Is this correct? Back to Your Specific Problem You said the problem wasthe reduction_per stat not being set correctly. Looking at your worker, tere is this code: 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}); It looks like reduction_per depends only on reduction and reduction_max, so I'd look at those stats and see if they are being calculated properly. It looks like reduction_per shows a percentage (hence the _per part of the name). In the sheet, both of these stats are readonly. How are they being set? Aha I think I see your issue. reduction is being set in this worker, so it looks like your issue is being caused by having separate setAttrs statements. Try the corrected worker above and see if this fixes the issue. The fact that you have change:reduction in a worker where reduction is also set could be a problem - this may create an infinite loop. It'll probably run just once extra, but if it does cause an infinite loop this is your issue.
I cant tell if this is working properly, but it looks like that the first line creates a data variable, but the later lines are based on a different format. This create an initial variable:  var data = {0:0,1:0}, this means data[0] = 0:0, and data[1] = 1:0, but the if statements later set a simple integer, 1, 2, 3, etc. Is this correct? Yes, you're correct. I think there's no problem here. It used to work properly. var red_effect = getreduction_effect(t_reduction); // what is this function? Sorry, I genuinely have no idea. And unfortunately, when I edited it with your code, my character sheet stopped working. Maybe I need to change other specific parts in front of the code as well, but this is such a big deal so I'm afraid to ask for help. I'll find out more about it myself. Thank you for your kindness.