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

Tongues script crashes when no token selected

I'm using version 4.5.2 of the Tongues script which should insert a default speaker name into the message when no token is selected and the GM uses a !tongues <language> <message> command, but attempting to do so crashes the sandbox with the following error. TypeError: Cannot read property 'get' of null at getTokenName (apiscript.js:750:26) at translate (apiscript.js:639:23) at commandSpeak (apiscript.js:568:25) at handleInput (apiscript.js:825:21) 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:1663: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) Anyone familiar enough with this script to know what's causing the crash?
1621246922

Edited 1621246967
Oosh
Sheet Author
API Scripter
A quick and dirty solution is to use optional chaining to change line 473: var name = token.get('name'); to this: var name = token?.get('name'); A better solution might look at why a null value is being passed to the getTokenName function, but you should at least get the fallback name returned with the above change. :)
Since we're talking Tongues... I just installed it in a new game, and I'm stumped as to why it's repeatedly kicking back an error when it works just fine in my other game...  Any ideas on what would be generating this? It's definitely from Tongues, as disabling it makes this error go away, and enabling it returns the error every single time. TypeError: Cannot read property 'length' of null TypeError: Cannot read property 'length' of null at apiscript.js:12288:53 at /home/node/d20-api-server/api.js:830:7 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) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Rd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400 at S (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:57:1015) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:380
@Oosh, I tried out the change you suggested but it prevented the API from starting up properly. The console gave me this error: SyntaxError: Unexpected token '.'
1621289260
Oosh
Sheet Author
API Scripter
Ah whoops, sorry! I didn't realise Roll20 doesn't support optional chaining. I was sure I'd used it before, but my memory isn't what it used to be. At least, I don't think it is? Try this instead, it should stop most invalid values from causing trouble: var name = (token && typeof(token) === 'object') ? token.get('name') : null;
That's got it working properly, Oosh, thanks so much for your help!
1621422380

Edited 1621422405
Oosh
Sheet Author
API Scripter
No problem! Craig M. said: Since we're talking Tongues... I just installed it in a new game, and I'm stumped as to why it's repeatedly kicking back an error when it works just fine in my other game...  Any ideas on what would be generating this? It's definitely from Tongues, as disabling it makes this error go away, and enabling it returns the error every single time. TypeError: Cannot read property 'length' of null TypeError: Cannot read property 'length' of null at apiscript.js:12288:53 at /home/node/d20-api-server/api.js:830:7 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) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Rd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400 at S (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:57:1015) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:380 Hi Craig, there are a load of .length uses in the Tongues script and you've obviously got a whole bunch of other scripts running (or one immense one!). That's a bit of a needle-in-a-haystack hunt. Unless one of the proper coders around here can glean something from the Firebase stack to narrow it down... that's definitely beyond me though, sorry!
1621429747

Edited 1621429761
The Aaron
Roll20 Production Team
API Scripter
It's happening inside loadHandout() because of these lines: 1 2 3 4 var matches = notes . match ( /(\[.*?\])/igm ); languages [ languageName ]. dictionary = {}; languages [ languageName ]. vocabulary = []; for ( var i = 0 ; i < matches . length ; i ++ ){ line 1 above looks for something in [ ] in the notes, then operates on each of them on line 4 above.  .match() returns null if there isn't a match to regular expression, and line 4 is calling .length on it. You should look at the format in your languages handouts, or look for a handout it will think is a language handout and fix the format or rename the rogue handout, and that should clear it up.
When you need to find a needle in a haystack, call.... The Aaron™!!!! Thank you as always, sir!
1621438243
The Aaron
Roll20 Production Team
API Scripter
No problem. =D  The null was a big hint because there are very few things in Javascript that actually return it, and Regexp.match() is the number one culprit. =D
That's super useful to know! I'll need to remember that for future troubleshooting :)