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

[Sheet Workers] Trouble accessing min or max result

I got a sheet worker finding the lower of two numbers.  Now, when I try to access that number, I get an NaN result.  What am I doing wrong? Code to find the low number: on('change:cog_max change:cog_morph_max change:coo_max change:coo_morph_max change:int_max change:int_morph_max change:ref_max change:ref_morph_max change:sav_max change:sav_morph_max change:som_max change:som_morph_max change:wil_max change:wil_morph_max sheet:opened', function() {     getAttrs(['cog_max', 'cog_morph_max', 'coo_max','coo_morph_max', 'int_max','int_morph_max', 'ref_max','ref_morph_max','sav_max','sav_morph_max', 'som_max','som_morph_max', 'wil_max','wil_morph_max'], function(values) {         setAttrs({              cog_apt: Math.min(+values.cog_max, +values.cog_morph_max),             coo_apt: Math.min(+values.coo_max, +values.coo_morph_max),              int_apt: Math.min(+values.int_max, +values.int_morph_max),              ref_apt: Math.min(+values.ref_max, +values.ref_morph_max),              sav_apt: Math.min(+values.sav_max, +values.sav_morph_max),              som_apt: Math.min(+values.som_max, +values.som_morph_max),               wil_apt: Math.min(+values.wil_max, +values.wil_morph_max)                      });     }); }); And code trying to access said number: on("change:skill_select change:skill_base sheet:opened", function() {         getAttrs(["skill_select", "skill_base", "skill_total"], function(values) {         if (values.skill_select == 0) {             setAttrs({                  skill_total: 0             })         }         if (values.skill_select == 1) {             setAttrs({                  skill_total: +values.skill_base + +values.cog_apt             })         }         else if (values.skill_select == 2) {             setAttrs({                  skill_total: +values.skill_base + +values.coo_apt             })         }         else if (values.skill_select == 3) {             setAttrs({                  skill_total: +values.skill_base + +values.int_apt             })         }         else if (values.skill_select == 4) {             setAttrs({                  skill_total: +values.skill_base + +values.ref_apt             })         }         else if (values.skill_select == 5) {             setAttrs({                  skill_total: +values.skill_base + +values.sav_apt             })         }         else if (values.skill_select == 6) {             setAttrs({                  skill_total: +values.skill_base + +values.som_apt             })         }         else if (values.skill_select == 7) {             setAttrs({                  skill_total: +values.skill_base + +values.wil_apt             })         }    }); });
I am no expert and have only written  copied and modified basic sheet workers so far, but the ones that work all use value.something to evaluate, not values.something.
1475900032

Edited 1475901204
Lithl
Pro
Sheet Author
API Scripter
Rabulias said: I am no expert and have only written  copied and modified basic sheet workers so far, but the ones that work all use value.something to evaluate, not values.something. values  or value  is the name of the parameter in the anonymous function of getAttrs. Because CPP has values  as the name of the parameter, that's the correct name to use. @CPP: What are the actual max values when you get NaN back, and is that the default value for the field, or something that's been filled in? Also: While the unary identity operator (+x) can be used to coerce strings to numbers, it fails (either with NaN or with unexpected behavior) on a wider array of input values than parseInt does. Edit: Here's a comparison I wrote up on Stack Overflow about +x as parseInt just under three years ago: +'150' // 150 +'150z' // NaN +'z150' // NaN +'015' // 15 in EMCAScript >= 5, 13 in EMCAScript < 5 +'015z' // NaN +'z015' // NaN +'0xf' // 15 -- note that it interprets as hexadecimal +'0xfz' // NaN +'z0xf' // NaN +'NaN' // NaN +'undefined' // NaN parseInt('150') // 150 parseInt('150z') // 150 parseInt('z150') // NaN parseInt('015') // 15 in EMCAScript >= 5, 13 in EMCAScript < 5 parseInt('015z') // 15 parseInt('z015') // NaN parseInt('0xf') // 15 -- note that it still interprets as hexadecimal parseInt('0xfz') // 15 parseInt('z0xf') // NaN parseInt('NaN') // NaN parseInt('undefined') // NaN +[] // 0 +[150] // 150 +['150'] // 150 +['150z'] // NaN +[1, 2] // NaN +{} // NaN +null // 0 +true // 1 +false // 0 +NaN // NaN +undefined // NaN +function(){} // NaN
Okay, I messed up the getAttrs area, and the code didn't know what attributes I was asking for. Thanks for yawl's input. And Brian...I have no idea what most of what you put means.  I am self-taught, and my teacher sucked.