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

API TypeError, Can't get it resolved

Hello there, So I have been playing through a small campaign with friends and I have to regularly restart the API when I'm using !ta from TokenAction and using commands from TokenMod. Whenever I do, it puts the campaign on an error lock with the following error: TypeError: Cannot read property 'push' of undefined TypeError: Cannot read property 'push' of undefined     at apiscript.js:6166:27     at Function.each (/home/node/d20-api-server/node_modules/underscore/underscore.js:188:9)     at createSpell (apiscript.js:6140:15)     at apiscript.js:6327:29     at Function.each (/home/node/d20-api-server/node_modules/underscore/underscore.js:188:9)     at handleInput (apiscript.js:6284:19)     at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16)     at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:70:8)     at /home/node/d20-api-server/api.js:1661:12     at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 I tried finding this "push" property, but as I am noob at reading code, I can only get to the assumption that its from the Bump script, even though I have it disabled and I'm lost as to why it only occurs as I use !ta. Any ideas on how to keep this error from occurring? Here is a screenshot of the scripts I have active on my game (this a new copy of an old game and the scripts that are active are the only scripts that have ever been active on this version):
1595726080
The Aaron
Roll20 Production Team
API Scripter
The issue is in TokenAction on line 173 where it pushes a button into the listing for that level.  Some how, the level it's finding is not matching any of the predefined levels, so the reference sb[level] is returning undefined, which then has .push() called on it.  You can correct your copy by changing the if block on lines 151-171 to: if (level === "1") { level = "1st"; } else if (level === "2") { level = "2nd"; } else if (level === "3") { level = "3rd"; } else if (level === "4") { level = "4th"; } else if (level === "5") { level = "5th"; } else if (level === "6") { level = "6th"; } else if (level === "7") { level = "7th"; } else if (level === "8") { level = "8th"; } else if (level === "9") { level = "9th"; } else level = "Cantrips"; } which will force it to put anything it doesn't know into the Cantrips list.  Probably it's a case issue, but it should become apparent after that.  I'll pass this on to Keith and see what he makes of it.
Sorry that I'm gonna sound like an idiot, but how do I edit the script directly? I added the TokenActionMaker script through the standard Roll20 library so for some reason its letting me enter and edit the script.
1595744326
The Aaron
Roll20 Production Team
API Scripter
No worries. You'd remove it, then find it in the 1-click and choose import instead of install. Then you can edit it. Once it's fixed in the 1-click, you'll delete your imported and modified copy and re-install it from the 1-click. 
1595745641
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Thanks Aaron, and thanks Lucas for reporting it. I'll put that fix in (plus one more, I believe) for the next pull. That's one of the sections I did not write, son Aaron's instinct on this is probably 900 times better than mine.
1595746593
GiGs
Pro
Sheet Author
API Scripter
Make sure to add the missing { in this one                 } else { // <-- here level = "Cantrips"; } This is a shocking day. The Aaron is in fact mortal.
1595747503

Edited 1595747515
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Works fine, but if you try this Lucas, the third to last line should be:                 } else { It was missing an open bracket. I just had to point this out because the chances I get to correct a coding error by the Aaron are about as rare as teeth on a duck. And to be fair, I just got off a full day of OT work and a game session, so I just put in the changes and ran a quick battery of tests, without bothering to figure out why it was broken. :/ The Aaron just breathes in problems and exhales code. Thanks again.
1595747984
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Aaaand GiGs beat me to it. :D
1595774554
The Aaron
Roll20 Production Team
API Scripter
GiGs said: Make sure to add the missing { in this one                 } else { // <-- here level = "Cantrips"; } This is a shocking day. The Aaron is in fact mortal. Hahahahaha!  That's what I get for hacking code on my phone... =D
Wow thanks everyone for the help!