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

[SheetWorker] mixing auto-calc with SheetWorkers for BaB and Saves

My sheet uses some hidden fields and dropdown menues to simplify the process of keeping track the leveling process.  Not that it particullarly difficult, but it does aid in altering npcs on the fly.  However, it has created some issues with converting my sheets fully to SheetWorkers.  I was wondering if there was any way to cheat, fake or otherwise trick the SheetWorkers into accepting auto-calcs and other similar things. I know that the Pathfinder Sheet has some interaction between autocalcs and sheet workers for the HP Formula and skill ranks formula, so I know something like what I want is possible.  At the very least having the SheetWorker match the string in the field and shove the correct formula in its place. The racial has drop-down selections for BAB and Saves, which I could easily convert into SheetWorkers, but the class choices have a regular field which uses hidden fields with formula for each.  I do this because I want to allow players to enter the number manually, and I want to be able to use this auto-calc to create NPCs that I can increase in level on the fly. I am fairly certain I know a few ways to get a similar effect, the problem is the 300+ character sheets that use the above method.  I can't really think of any way convert the BAB and Saves to SheetWorkers without causing a massive headache and telling people I need like a month off to convert all sheets to the new system. Any assistance in this would be appreciated.
1508413733
Jakob
Sheet Author
API Scripter
The canonical solution would be to just use sheet workers for everything - I don't see how the number of sheets is an issue, you only need to write the new code once? Anyway, if you want to mix sheet workers and auto-calculating fields, you may be interested in  this .
the reason the number of sheets matters is because I would have to go through all every single one of those sheets and update them.  Which is something I refuse to do unless I have exausted every single alternative.
1508443369
Finderski
Pro
Sheet Author
Compendium Curator
I think what Jakob is getting at, is you write the code once, it's on all the character sheets at that point. Because Sheet Workers are event triggered, you could have an event for when the sheet is opened and let the sheet worker do all the work for you, wouldn't have to update any fields or sheets at that point. It may be easiest to just have a sheet worker do the same calculations as the Calc Fields do today and move away from calculated fields all together.
I wouldn't even know where to begin to create an auto updating thing like that.  And, I agree with you, I would love to be able to do that, and I am trying to work on something where it takes the @{fa-bab-#} and then resolves that as the correct formula inside of the sheet worker.  At least that is my current angle.  So far I'm not having much luck. There are two helper snippets I have found that looked promising, the autocalc code Jacob pointed me to and SWUtils, which I have seen at work elsewhere, and didn't really understand.  The former just isnt working at all, and the latter doesnt seem to be able to manipulate the autocalc fields, just grab them and convert them and spit them back out straight to a readonly field.  Which means I'd have to create a ton of hidden fields. What I have now is using the following code to learn how to get the resolveautocalc() works. on('sheet:opened change:PwrAtk change:PwrAtk-toggle', function() { console.log("============= Pull BAB =============");     resolveAutocalc(['PwrAtk', 'PwrAtk-toggle', 'BAB'], function(v) { var bab = v["BAB"], IsOn = parseInt(v["PwrAtk-toggle"],10||0); var PAtkAtk = Math.min(Math.floor(bab/4),2)*2; var PAtkDam = Math.min(Math.floor(bab/4),1); // I am using bowstr-3 so I have somewhere to show it on the sheet, it is only temp while I learn the code. // I am not really sure whats going on but nothing after resolveAutocalc() seems to display.  Not even the //console logs are firing.  I'm probably screwing up the syntax.  And I have a feeling that going from bab //which is a string straight into PAAtk??? which are both integers may have something to do with it. setAttrs({             'bowstr-3': bab         }); console.log("The value of bab is: " +bab); console.log("The value of ATTACK is: " +PAtkAtk); console.log("The value of DAMAGE is: " +PAtkDam); console.log("Checkbox isOn: [" + IsOn +"]");     }); }); The ultimate goal of this script is to have a single checkbox to turn on and off power attack, then I will pass the power attack value to a repeating section field and check if the weapon is 1handed/2handed/nat primary or nat/secondary.  Instead of needing cumbersome roll-queries for every single time an attack roll is made.  I have the second half functioning mostly. And while I may not actually use this code for power attack, I thought it sufficiently simple a script to use to teach myself.
1508494478

Edited 1508494662
Jakob
Sheet Author
API Scripter
I don't know about the autocalc, but here's a simple version of how you do version upgrades. Here, the sheet is on version 3. ( Remark; ignore on first reading.  Note that this breaks down and has to be written somewhat differently if you depend on the asynchronous functions in earlier upgrades to be finished before you do later upgrades. It's not hard to take care of that, but I left it out to make the code simpler ). on("sheet:opened", function () {   getAttrs(['version'], function (v) {     const version = parseInt(v.version) || 0;     if (!version) {       // Do stuff here that you need to do to initialise a fresh sheet     }     else {       if (version < 2) {         // Do upgrades from version 1 to version 2       }       if (version < 3) {         // Do upgrades from version 2 to version 3       }     }     setAttrs({       version: '3'     });   }); }); Since you didn't have versioning earlier, you will have to run your conversion code inside the if (!version)  block. Inside, you would run functions that calculate BAB and all dependent fields. Bonus - not necessary.  If you don't feel like opening 300 sheets (since this code only runs when a sheet is opened), here's a way to do it in the background. Replace the event string by "sheet:opened change:toggle_upgrade_manually". Then, run the following command using ChatSetAttr: !setattr --all --toggle_upgrade_manually|1
I have spent the past two days playing around with the above code and found that I have fallen in love with this idea.  This is amazing and solves 99.999% of all my problems in once instantaneous button push.  However, there is one tiny snag I have run into when trying to execute this.  I have my code to handle my new BAB / SAVES input style, and I have the code to update it.  However, both sets of code is NASTY long and wordy. Hopefully this question will be far and a way easier, than my previous ones.  And yes, I have converted the BAB / SAVES from numeric fields to dropdown selection boxes.  This saves me alot of time when I need to scale up and down npcs, and my players time, when they level.  I have players that have to balance their game time with full time work and part time school + family, so the less the need to do apart from the roleplay the better.  This is my update code minus the above code: // Class 01 Fortitude Save Update Code without versioning on('sheet:opened change:class-0-bab', function() { //console.log("============= Set BAB Details =============");     getAttrs(['class-0-bab'], function(v) { var clsBAB_0 = v['class-0-bab'],   // Numeric Field clsBAB_00 = "";                // Selection Box if (v['class-0-bab'] === "@{fa-bab-0}") {    clsBAB_00 = "[[floor(@{class-0-level})]]";    console.log("============= SET BAB FAST =============");     } else if (v['class-0-bab'] === "@{me-bab-0}") {    clsBAB_00 = "[[floor(@{class-0-level} * 0.75)]]";    console.log("============= SET BAB SLOW ============="); } else if (v['class-0-bab'] === "@{sl-bab-0}") {    clsBAB_00 = "[[floor(@{class-0-level} * 0.5)]]";    console.log("============= SET BAB SLOW ============="); } else { return } console.log("=============" + clsBAB_00 + "============="); setAttrs({ 'class-00-bab': clsBAB_00         });     }); }); The style i'd like to use is: on('sheet:opened change:str-mod change:dex-mod ..... change:acrobatics-acp change:acrobatics-misc', _.bind(UpdateSkill,{},'Acrobatics')); Now assume I have five classes, class-0 though class-4 and I need to convert bab and each of the three saves.  Thats alot of if else statements...  I know there is a way to simplify it.  I use the code already for my skills, I just dont really understand it all that well since someone else helped with the skills and used some understore.js and callbacks. Any chance someone could point me in the right direction.