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

Auto Calc minimum 1?

1670721349

Edited 1670721428
I'm trying to prevent this field from calculating into negative numbers.   Currently it references the level {attr_psi_body_discipline}, if this gets too high then the autocalc goes below 0.  Yes, I know it should be a sheetwork/JS thing.  value="floor(8-(floor(@{psi_body_discipline}*0.1)))" <input class="sheet-inputfield sheet-center sheet-blue-color" style="width:75px;" name="attr_psi_body_discipline_boost_str_cost" value="floor(8-(floor(@{psi_body_discipline}*0.1)))"   type="number" min="1" disabled/>                        
1670721387

Edited 1670721437
value="floor(8-(floor(@{psi_body_discipline}*0.1)))"
1670722254

Edited 1670722367
GiGs
Pro
Sheet Author
API Scripter
Personally, I'd suggest skipping autocalcs and using sheet workers, but that's trickier. Note that the min tag in html does nothing in roll20, so you can ignore that. I was going to give an autocalc solution, but I cant remember if the {calculation,1}kh1 method works in autocalcs. I would say that you should erase the first floor as its not needed (keep the brackets) So here's a sheet worker: on ( 'change:psi_body_discipline sheet:opened' , () => {     getAttrs ([ 'psi_body_discipline' ], v => {         let psi = + v . psi_body_discipline || 0 ;         let str_cost = Math.floor ( psi / 10 );         str_cost = Math . max ( 1 , 8 - str_cost );         setAttrs ({             attr_psi_body_discipline_boost_str_cost : str_cost         });     }); }); Remember to put that in your script block. If you dont have one, thats a section placed at the end of your html that looks like this: <script type="text/worker"> //all sheet workers go here. </script>
1670722677
GiGs
Pro
Sheet Author
API Scripter
Also change your html from this <input class="sheet-inputfield sheet-center sheet-blue-color" style="width:75px;" name="attr_psi_body_discipline_boost_str_cost" value="floor(8-(floor(@{psi_body_discipline}*0.1)))"   type="number" min="1" disabled/>     to this <input class="sheet-inputfield sheet-center sheet-blue-color" style="width:75px;" name="attr_psi_body_discipline_boost_str_cost" value=""   type="number" readonly/>     Note that sheet workers cant change elements that are set to disabled - use readonly in those cases. Also in that html you have used a bunch of classes, so I recommend creating another class lkie .charsheet .width75 { width: 75px; } and adding that to your html like so <input class="sheet-inputfield sheet-center sheet-blue-color sheet-width75" name="attr_psi_body_discipline_boost_str_cost" value=""   type="number" readonly/>     You'll easily be able to add that width to other elements, and if you changed the name from width75 to something like width-medium you'd have a number you could easily change and update in multiple places on the sheet at once. Also look into using CSE mode when writing sheets (Character Sheet Extensions) so you dont have to include sheet- with your class names. Its not hard to change.
Sheetworker is coming back blank in the field. What does the v => mean?
GiGs said: Also change your html from this <input class="sheet-inputfield sheet-center sheet-blue-color" style="width:75px;" name="attr_psi_body_discipline_boost_str_cost" value="floor(8-(floor(@{psi_body_discipline}*0.1)))"   type="number" min="1" disabled/>     to this <input class="sheet-inputfield sheet-center sheet-blue-color" style="width:75px;" name="attr_psi_body_discipline_boost_str_cost" value=""   type="number" readonly/>     Note that sheet workers cant change elements that are set to disabled - use readonly in those cases. Also in that html you have used a bunch of classes, so I recommend creating another class lkie .charsheet .width75 { width: 75px; } and adding that to your html like so <input class="sheet-inputfield sheet-center sheet-blue-color sheet-width75" name="attr_psi_body_discipline_boost_str_cost" value=""   type="number" readonly/>     You'll easily be able to add that width to other elements, and if you changed the name from width75 to something like width-medium you'd have a number you could easily change and update in multiple places on the sheet at once. Also look into using CSE mode when writing sheets (Character Sheet Extensions) so you dont have to include sheet- with your class names. Its not hard to change. The field comes back blank :( I'm trying to go through your JS, and I understand some, but the v => and a few others I'm not getting.
1670734655
GiGs
Pro
Sheet Author
API Scripter
If its coming as blank, that means I have made an error or there's an error in the way you have set it up. The syntax for the sheet worker seems to be correct, so can you post the full html page on pastebin? The => method is using something called Fat Arrow syntx. If you look at older sheet workers, you'll see them written like on ( 'change:psi_body_discipline sheet:opened' , function() {     getAttrs ([ 'psi_body_discipline' ], function(v ) {         let psi = + v . psi_body_discipline || 0 ;         let str_cost = Math.floor ( psi / 10 );         str_cost = Math . max ( 1 , 8 - str_cost );         setAttrs ({             attr_psi_body_discipline_boost_str_cost : str_cost         });     }); }); Basically the => replaces having to type function every time. There are fairly obscure benefits for using the arrow syntax over the old style, but for practical purposes it doesn't really make any other difference, it's just a slightly more efficient method of writiing them.
1670734723
GiGs
Pro
Sheet Author
API Scripter
Michael D. said: The field comes back blank :( This should be blank on its own - it relies on the sheet worker to populate it, and if something is making the sheet worker fail, it will be empty.
1670734839

Edited 1670734903
GiGs
Pro
Sheet Author
API Scripter
aha, I see an error in my code which is almost certainly the problem. The attr_ is not part of the attribute name (in setAttrs), I made a copy/paste error. Try this: on ( 'change:psi_body_discipline sheet:opened' , () => {     getAttrs ([ 'psi_body_discipline' ], v => {         let psi = + v . psi_body_discipline || 0 ;         let str_cost = Math.floor ( psi / 10 );         str_cost = Math . max ( 1 , 8 - str_cost );         setAttrs ({             psi_body_discipline_boost_str_cost : str_cost         });     }); }); Or on ( 'change:psi_body_discipline sheet:opened' , function() {     getAttrs ([ 'psi_body_discipline' ], function(v ) {         let psi = + v . psi_body_discipline || 0 ;         let str_cost = Math.floor ( psi / 10 );         str_cost = Math . max ( 1 , 8 - str_cost );         setAttrs ({             psi_body_discipline_boost_str_cost : str_cost         });     }); });
GiGs said: aha, I see an error in my code which is almost certainly the problem. The attr_ is not part of the attribute name (in setAttrs), I made a copy/paste error. Try this: on ( 'change:psi_body_discipline sheet:opened' , () => {     getAttrs ([ 'psi_body_discipline' ], v => {         let psi = + v . psi_body_discipline || 0 ;         let str_cost = Math.floor ( psi / 10 );         str_cost = Math . max ( 1 , 8 - str_cost );         setAttrs ({             psi_body_discipline_boost_str_cost : str_cost         });     }); }); Or on ( 'change:psi_body_discipline sheet:opened' , function() {     getAttrs ([ 'psi_body_discipline' ], function(v ) {         let psi = + v . psi_body_discipline || 0 ;         let str_cost = Math.floor ( psi / 10 );         str_cost = Math . max ( 1 , 8 - str_cost );         setAttrs ({             psi_body_discipline_boost_str_cost : str_cost         });     }); }); Derp! I should have seen that! THANKS!
1670758085
GiGs
Pro
Sheet Author
API Scripter
Michael D. said: Derp! I should have seen that! THANKS! You're welcome :)