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 .
×
D&D 2024 has arrived! Pre-Order the new core rulebooks now.
Create a free account

[HELP] Sheet Workers for Autocalc not working

1470352398
Finderski
Pro
Sheet Author
Compendium Curator
So, I'm trying to figure out why a Sheet Workers isn't working on a particular character sheet.  It seems to be only one character that is having the problem (at least I haven't been able to replicate it on any other character), and the Developer Console is woefully unhelpful (at least for me).  So, before I recommend that the player just fill out a new character sheet, I thought I would ask the collective for help in seeing if this is a problem with my Sheet Worker, or if there is something else that may be going on... The Issue :  totalloadcarried and encumbrance resolve to NaN when adding weight values to the various forms of equipment. The total weight calculates properly, but the attributes mentioned above, always resolve to NaN. I do use TheAaronSheet sheet worker do do the sums for the various weights.  Following the TAS, I have these sheet workers to calculate Load Carried and Encumbrance penalty: //Calculate Total Load Carried on("sheet:opened change:armortotalweightcarried change:meleetotalweightcarried change:rangedtotalweightcarried change:geartotalweightcarried",function(){ getAttrs(["armortotalweightcarried", "meleetotalweightcarried", "rangedtotalweightcarried", "geartotalweightcarried"], function(lvalue) { var armor = parseInt(lvalue.armortotalweightcarried); var melee = parseInt(lvalue.meleetotalweightcarried); var range = parseInt(lvalue.rangedtotalweightcarried); var gear = parseInt(lvalue.geartotalweightcarried); setAttrs({ totalloadcarried: armor + melee + range + gear }); }); }); //Calculate Encumbrance Penalty on("sheet:opened change:loadlimit change:totalloadcarried change:loadlimit",function(){ getAttrs(["loadlimit", "totalloadcarried"], function(lvalue) { var load = parseInt(lvalue.totalloadcarried); if (load === 0) { load = 1; //If there is no current load, then need to set it to 1, so the result of the calc = 0 } var limit = parseInt(lvalue.loadlimit);    setAttrs({ encumbrance: Math.floor((limit - load) / limit) }); }); }); As I've said, those seem to work for me and I can't replicate the issue.  While on that character, the developer console logs report: I have no idea what that means, so I'm hoping someone here can help me pinpoint where the issue may be. In reviewing the character, I see no values that would cause this to fail (i.e. all the necessary values are numbers, enforced by the character sheet). Short of just adding a new character and moving data over, can anyone help me figure out what's going on? If there is something wrong with the sheet worker scripting, I would like to resolve that, but none of the TAS error capturing stuff is making it to the log and when I can't see anything with with the load limit and encumbrance script. Help, please. :)
I am no coder, but did you check the attributes on the Attributes & Abilities tab instead of the sheet? There might be an attribute from an earlier sheet with the same name that contains non-numeric info.
1470365112
Finderski
Pro
Sheet Author
Compendium Curator
Rabulias said: I am no coder, but did you check the attributes on the Attributes & Abilities tab instead of the sheet? There might be an attribute from an earlier sheet with the same name that contains non-numeric info. Great question. Yes, and I've deleted the fields and let the sheet recreate them. Same problem. 
1470365640
The Aaron
Pro
API Scripter
Use this construct when you parseInt(): parseInt(lvalue.armortotalweightcarried,10) ||0 ; parseInt() returns undefined for something that isn't a number. When you add undefined to a number, you get NaN. The ||0 on the end will replace the undefined with 0, preventing the issue.  TheAaronSheet has some special transforms for parsing attributes into various formats, see the docs on the github (or the original forum posts). Feel free to ping me if you have any questions (but I'm at GenCon, so expect latency!)
1470365988

Edited 1470366006
Lithl
Pro
Sheet Author
API Scripter
The Aaron said: parseInt() returns undefined for something that isn't a number. When you add undefined to a number, you get NaN. The ||0 on the end will replace the undefined with 0, preventing the issue. parseInt returns NaN for something that's not a number. Since that's what NaN stands for. =P
1470367264
The Aaron
Pro
API Scripter
Good enough. :). 
1470368712
Finderski
Pro
Sheet Author
Compendium Curator
Awesome! Thanks.