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

[Question] In what way would I catch a NaN value?

In this specific example, I'm pulling "bar3_value" from a token, then parsing it into a number. How would I catch it before it throws the error, causing my script to fail? For example: var truemod = parseInt(obj.get("bar3_value")); is what I have, but that (of course) throws an error if bar3_value is NaN. In case I'm just misunderstanding, this is the error I'm getting: /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function f(a){throw a;}var j=v ^ Error: Firebase.update failed: First argument contains NaN in property 'bar3_value' at Error (<anonymous>) at Aa (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:9:186) at Aa (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:196) at za (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:8:468) at Da (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:392) at G.W.update (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:128:318) at TrackedObj._doSave ( EDIT: SO many typos, fixed them.
if (obj.get("bar3_value") == NaN) return; should stop it for example when it's NaN, can do other stuff instead of return obviously.
Ah... that's what I thought. Turns out what was happening was that I was special, and wasn't using that to set bar3_value to 0... so when the script tried to access it again, it was still coming up NaN. Thank you!
You can also use _.isNaN()
Oh... that's really cool. Thanks, Riley! That's one of the things I really like about the whole Roll20 Model - getting help directly from a dev is just... awesome.