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

Script not adding a value

Hello,  So i have been working on a sheet for a long time now and i have been learning a lot with everyone's help. With that said i dont know why one of my scripts is not working. i need it to add up the value of other inputs but it does not seem to work. can some one take a look and tell me what im doing wrong?  I can get the prb scripts to work but i cant get the script that would add the values of the three together to work.  <input  type="text"    class="Power_Text_2"  name="attr_prb1t"                                                  readonly /> <input  type="text"    class="Power_Text_2"  name="attr_prb2t"   readonly /> <input  type="text"    class="Power_Text_2"  name="attr_prb3t"    readonly /> <input  type="text"    class="Power_Text_2"  name="attr_pr"                                                  readonly /> <script type="text/worker"><!-- Combat Focus Damage -->      on('change:PsychicGift_Checkbox', function () {          getAttrs(['PsychicGift_Checkbox'], function (v) {      const sumTotal = parseInt(v.PsychicGift_Checkbox); setAttrs({      prb1t: sumTotal              });          });      }); </script> <script type="text/worker"><!-- Combat Focus Damage -->      on('change:Psychic_Training_1_Checkbox', function () {          getAttrs(['Psychic_Training_1_Checkbox'], function (v) {      const sumTotal = parseInt(v.Psychic_Training_1_Checkbox); setAttrs({      prb2t: sumTotal });      }); }); </script> <script type="text/worker"><!-- Combat Focus Damage -->      on('change:Psychic_Training_2_Checkbox', function () {          getAttrs(['Psychic_Training_2_Checkbox'], function (v) {              const sumTotal = parseInt(v.Psychic_Training_2_Checkbox); setAttrs({              prb3t: sumTotal });      }); }); </script> <script type="text/worker"><!-- Combat Focus Damage -->      on('change:prb1t change:prb2t change:prb3t', function (value) {          getAttrs(['prb1t','prb2t','prb3t', function (value) {      const prb1t = parseInt(value.prb1t);      const prb2t = parseInt(value.prb2t);      const prb3t = parseInt(value.prb3t);      const sumTotal = prb1t + prb2t + prb3t; setAttrs({      pr: sumTotal });      }); }); </script>
1690926120

Edited 1690927612
GiGs
Pro
Sheet Author
API Scripter
Not related to the specific problem, but you should have only one script block, and all your workers put inside that. When you have simple sheet workers like these, it's not so important, but it's still a little neater and easier to work with. later on as you start adding global functions meant to be used in more than one sheet worker, you'll hit real problems like this. On to your specific problem. You have a missing close bracket in getAttrs. This line: getAttrs(['prb1t','prb2t','prb3t', function (value) { should be getAttrs(['prb1t','prb2t','prb3t'], function (value) {
1690926226

Edited 1690927650
GiGs
Pro
Sheet Author
API Scripter
Also this is incorrect (though not damaging here - but it will be later) <script type="text/worker"><!-- Combat Focus Damage --> This syntax <!-- --> is for comments in html, but inside a script block, you are working in javascript so should use one of the following: <script type="text/worker">// Combat Focus Damage <script type="text/worker">/* Combat Focus Damage */
1690926572

Edited 1690927684
GiGs
Pro
Sheet Author
API Scripter
Looking at your first 3 sheet workers, I wonder if they are needed. You can put the same attribute in multuple places simply by copying the entire input there, with the same name. You can make the copies readonly, so players can only change the original input. You can also have the original be a checkbox and later ones be number or text. I would recommend changing these attributes to type="number" - best to use that in place of text unless you are expecting text.
Cool that worked thank you i did not see that. you are the best. also I got everything to work out of one script like you suggested. and i use test instead of number alot of times in places where i dont want the up/down arrows to show up. there are places where they are necessary like in places where player can adjust the number. 
1690984287

Edited 1690984881
GiGs
Pro
Sheet Author
API Scripter
You can hide the spinners (those up/down arrows) with CSS (I do this a lot, because I find them irritating too). Add a class to the inputs where you want to hide it: <input  type="number"    class="Power_Text_2 noarrow"  name="attr_prb2t"   readonly /> Then create the CSS class (in your CSS file) .charsheet input [ type = number ] .noarrow {     -moz-appearance :textfield;     text-align : center ; } (The center alignment is optional). If you want to apply this to all inputs, without needing a class, just remove the class .charsheet input [ type = number ] {     -moz-appearance :textfield;     text-align : center ; } This way you get the benefit of treating it like a number field, without the spinners. Note: if an input is text, that means people can (somnetimes accidnetally) enter the wrong values, which will break your sheet workers. So it's better to stick to number if your input is meant to just take umber data.
1690984627

Edited 1691008239
GiGs
Pro
Sheet Author
API Scripter
I also do it for selects, because I think the dropdown arrow there is usually redundant: select.noarrow {     -webkit-appearance : none ;     -moz-appearance : none ;     text-indent : 1px ;     text-overflow : '' ; } It needs different styles to account for different browsers. You don't need the text-indent, but I like a little bit - the amount varies with the sheet's font size. You might want to replace that with a center alighnment, and/or removing padding . There's a lot you can do with styling.
1690992238
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Like GiGs, I also tend to remove those bits of numbers and selects, but I usually just do it as a global change, and then add them back in the ultra rare instances where I actually want them.
ok i will have to add that to the list to give a try. thank you i do hate those arrows.