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 .
×
Advertisement Create a free account

[question] how can i auto-calculating?

1627202634
I'm asking a question because there was a problem while making the one-way heroic's sheet. What I want to make is [LIFE increase by level](a)+[LIFE increase by item](b)=[total LIFE] (c) <like that! So I made this <input>&Script, but isn't can working😥 what can i do?   <div   class = "sheet-stat_col1" >      <span> LIFE </span>      <input   type = "number"   class = "sheet-level_sum"   name = "attr_LIFE_LV"   value = "0" >      <input   type = "number"   class = "sheet-item_sum"   name = "attr_LIFE_fix"   value = "0" >      <input   type = "number"   value = "0"   name = "attr_LIFE_max"   disabled >   </div> <script   type = "text/worker" >   on("change:LIFE_LV, function(){     getAttrs(["LIFE_LV","LIFE_fix"],function(values){     setAttrs({LIFE_max:Number(values.LIFE_LV)+Number(values.attr_LIFE_fix);});     ;});   }); </script>
1627203335
GiGs
Pro
Sheet Author
API Scripter
The following line contains a number of syntax errors: setAttrs({LIFE_max:Number(values.LIFE_LV)+Number(values.attr_LIFE_fix);}); it should be setAttrs({     LIFE_max:Number(values.LIFE_LV)+Number(values.LIFE_fix) }); I added the line break to make it easier to read and spot the errors. But you had the attr_ in LIFE_fix, which shouldnt be there, and a semi-colon that shouldnt be there too. There's also a syntax error on the on(change) line - attributes there must be lower case (even if they arent in the html). Since this is confusing, its common advice to always use lower case everywhere for attribute names. You don't need to in the html, but its a good idea in your sheet workers. I'd also avoid putting calculations in the setAttrs function - it makes it very hard to analyse errors. Something like this would be better: <script   type = "text/worker" >   on("change:life_fv, function(){     getAttrs(["life_fv","life_fix"],function(values){         let life = Number(values.life_fv)+Number(values.life_fix);         setAttrs({             life_max: life });         });   }); </script> This allows you, if needed, to use console.log statements to check the value of an attribute. Like this:         let life = Number(values.life_fv)+Number(values.life_fix);         console.log('life = ' + life);         setAttrs({             life_max: life });     Then you could see if the lfe falue was being created and set to the proper value (when in your campaign, type f12 to see the console log - hit the console tab).
1627203423
GiGs
Pro
Sheet Author
API Scripter
Also, you'll need to change this line   <input   type = "number"   value = "0"   name = "attr_LIFE_max"   disabled > To this:   <input   type = "number"   value = "0"   name = "attr_LIFE_max"  readonly > This is because sheet workers cant modify disabled attributes.
1627203569
GiGs
Pro
Sheet Author
API Scripter
I see another problem. When life_fix changes, the value wont be updated. And that made me notice you dont have an end quote on the on change line. So here's an updated sheet worker: <script   type = "text/worker" >   on("change:life_fv change:life_fix", function(){     getAttrs(["life_fv","life_fix"],function(values){         let life = Number(values.life_fv)+Number(values.life_fix);         setAttrs({             life_max: life });         });   }); </script>
1627204656
It's working perfectly! Thank you so much!
1627205122
GiGs
Pro
Sheet Author
API Scripter
great! :)