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

One Click breaking, exact code runs in API Sandbox.

1646261194
Ernest P.
Pro
API Scripter
Hi. I recently merged an update into my ImportHS6e script, located here: <a href="https://github.com/Roll20/roll20-api-scripts/blob/master/ImportHS6e/1.03/Import_HS6e_Roll20.js" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/blob/master/ImportHS6e/1.03/Import_HS6e_Roll20.js</a> If I use the one click version of this in my sandbox and attempt to import characters, I get this error: For reference, the error message generated was: Error: Firebase.set failed: First argument contains NaN in property 'current' Error: Firebase.set failed: First argument contains NaN in property 'current' at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:9:186) at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:207) at Aa (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:8:462) at J.set (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:146:98) at createObj (/home/node/d20-api-server/api.js:2818:26) at createOrSetAttr (apiscript.js:1154:14) at createSimplePower (apiscript.js:1909:5) at apiscript.js:2243:9 at /home/node/d20-api-server/api.js:857:7 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 However, if I go to github and copy the js, name it the same and run it, it works perfectly. I changed nothing in the campaign other than deleting and manually importing this script from GIT. Can anyone give me a hint how to fix? The specific error is referencing the module at line 134 and as you can see I am already checking for NaN conditions on number fields. I might be able to code around this eventually, but testing will be long and complex since one click only updates once a week. - E
1646285548

Edited 1646286373
Oosh
Sheet Author
API Scripter
Are you checking for NaN though? I didn't look through all the code, but the place you're using createObj has this line: if(typeof objToSet === "number" &amp;&amp; IsNaN(val)) objToSet is the return from a findObjs array - it's always going to be "object" type, so this line will never progress past the &amp;&amp;. Which is lucky, because you have a typo which will also crash the sandbox. "isNaN" doesn't have a leading capital - this seems to be the only place you've mistyped it. You might want to look at your IDE setup - that's a pretty involved script to be coding in an environment that doesn't pick up undeclared variable names :) FWIW - eslint is showing 125 problems with the script. Some of them are just style issues, but a few of them look like they could cause undesired behaviour or a crash. For example, you have a double negation !! in an if() conditional. I'm assuming that's not intentional - I can't think of any functionality gained by negating a negation in JS, so presumably the conditional is exactly upside-down from what you want it to do. There's a host of variables that haven't been declared properly as well. Edit - if you are using a linter, safe to say that something's gone askew with it. A typo in the config JSON (or accidental deletion) will stop the linter from working completely, which may go unnoticed until you make an obvious error an wonder why it isn't highlighted in red.
1646323199
Ernest P.
Pro
API Scripter
I suppose now that I am up above 1k lines a linter would be desired. I currently hand code in Notepad. =P I still do not understand why the code will run as written if I paste the js and not through 1-Click? I'll look at eslint or something else to correct my other issues. I used the double negation for an implicit convert, which may not be needed in js, I work in several languages at the same time usually and sometimes concepts bleed over from one to another. - E
1646323279
timmaugh
Forum Champion
API Scripter
Oosh... that's some serious value you just dropped. Like dropping-from-the-top-rope-value. Well done. I will say that there is a periodic case to be made for the double-negation (!!), in that it can coerce a boolean from a string, number, etc., for places where "truthy" isn't good enough and you actually need boolean-True. Haven't looked at the code to know if that is the case for the line you reference, but I thought I'd throw it out there.
1646326953
GiGs
Pro
Sheet Author
API Scripter
Oosh said: For example, you have a double negation !! in an if() conditional. I'm assuming that's not intentional - I can't think of any functionality gained by negating a negation in JS, so presumably the conditional is exactly upside-down from what you want it to do. Just a minor clarification here - double negation is sometimes used in javascript to convert a value to a boolean: <a href="https://learn.coderslang.com/0165-what-is-a-double-negation-in-javascript-and-how-it-works/" rel="nofollow">https://learn.coderslang.com/0165-what-is-a-double-negation-in-javascript-and-how-it-works/</a>
1646410593
Ernest P.
Pro
API Scripter
I may have found the problem, but still absolutely no idea why it works in the local API but not one click. There are certain situations when calculating advantages and limitations when none are present that returned a NaN value. I am setting these to 0 in the return of the appropriate function and will request a pull over the weekend. - E&nbsp;
1646411354
Ernest P.
Pro
API Scripter
Oosh said: Are you checking for NaN though? I didn't look through all the code, but the place you're using createObj has this line: if(typeof objToSet === "number" &amp;&amp; IsNaN(val)) objToSet is the return from a findObjs array - it's always going to be "object" type, so this line will never progress past the &amp;&amp;. Which is lucky, because you have a typo which will also crash the sandbox. "isNaN" doesn't have a leading capital - this seems to be the only place you've mistyped it. You might want to look at your IDE setup - that's a pretty involved script to be coding in an environment that doesn't pick up undeclared variable names :) Thanks,&nbsp; @Oosh. I loaded Standard and ran it through, corrected all the non-style type bugs. I'll probably fix the style related to the extent I can as well, thanks for the tip. - E
1646420096

Edited 1646420121
timmaugh
Forum Champion
API Scripter
Ernest P. said: I may have found the problem, but still absolutely no idea why it works in the local API but not one click. There are certain situations when calculating advantages and limitations when none are present that returned a NaN value. I am setting these to 0 in the return of the appropriate function and will request a pull over the weekend. - E&nbsp; Probably an un-initialized attribute value. A character-sheet designer can tell you more, but I believe that just because the sheet has a field to hold a particular value doesn't mean that field has a value to the API. There are ways to force it to initialize to a particular value (like 0) in the sheet design, but if that isn't done, the field won't have a value in it until it is manually edited.