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

Difficulty Rating API Broken

As of last night the Difficulty Rating API is crashing when I select an NPC check for difficulty.   For reference, the error message generated was:  TypeError: Cannot read property '0' of undefined TypeError: Cannot read property '0' of undefined at apiscript.js:9241:28 at Array.forEach (<anonymous>) at GetPartyThresholds (apiscript.js:9238:38) at apiscript.js:9416:32 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:161:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:161:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1721:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
1624832450
The Aaron
Roll20 Production Team
API Scripter
Probably this function is where the problem is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 const GetPartyThresholds = () =&gt; { let easy = 0 ; let medium = 0 ; let hard = 0 ; let deadly = 0 ; state . DifficultyRating . Party . forEach (( player ) =&gt; { const level = player . Level ; const expTier = XPThresholds [ level - 1 ]; easy += expTier [ 0 ]; medium += expTier [ 1 ]; hard += expTier [ 2 ]; deadly += expTier [ 3 ]; }); return [ easy , medium , hard , deadly ]; } Someone in your party probably has a level that is either not set (undefined), or above 20, or below 1.&nbsp; That would cause the XPThresholds lookup to return undefined, and then would cause the expTier (undefined) to be dereference don a 0, causing the " TypeError: Cannot read property '0' of undefined " error. I patched the script and created a pull request to put the fix in the 1-click:&nbsp; <a href="https://github.com/Roll20/roll20-api-scripts/pull/1313" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/pull/1313</a> In the interim, you should re-set the levels on each of your players to make sure they are numbers between 1 and 20.
That totally worked.&nbsp; Thanks Aaron!