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

SyntaxError: Unexpected token else

So, uh. I do not get why I am getting this error. If / Else has always worked until now. on('chat:message', function(msg)  {     if (msg.type != 'api') return;     var parts = msg.content.split(' ');     var command = parts.shift().substring(1);     if (command == 'test')      {         var selectedId = parts[0];         var selectedToken = getObj('graphic', selectedId);         //Get the Name of tokens         var whoName = selectedToken.get('name');         var who = getObj('character', selectedToken.get('represents'));            if (!who)             {                 who = selectedToken.get('name');             }         if (getAttrByName(whoTarg.id, 'main_foc'.checked) = 'true');             {                 sendChat("Focus is checked");             }         else             {                 sendChat("Focus is not checked");             }     } });
1506243114
Jakob
Sheet Author
API Scripter
There's an extra semicolon on line 17. In general, it's a good idea to put your code into an external syntax validator ... the first web-based one google gives me is&nbsp; <a href="http://esprima.org/demo/validate.html" rel="nofollow">http://esprima.org/demo/validate.html</a> . It will give a more useful error message (+ line number) than Roll20.
Thanks that helps.
1506283612
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I also like the google closure compiler:&nbsp;<a href="https://closure-compiler.appspot.com/home" rel="nofollow">https://closure-compiler.appspot.com/home</a>
1506362634
Lithl
Pro
Sheet Author
API Scripter
Jakob said: There's an extra semicolon on line 17. In general, it's a good idea to put your code into an external syntax validator ... the first web-based one google gives me is&nbsp; <a href="http://esprima.org/demo/validate.html" rel="nofollow">http://esprima.org/demo/validate.html</a> . It will give a more useful error message (+ line number) than Roll20. To be fair, lines 1-21 are all syntactically valid, and the site you linked to gives the same error as Roll20. =) @Michael P: also, I would point out that the first parameter to sendChat is the name of the "person" sending the message, not the message itself. Line 17 also has a problem of using assignment (getAttrByName(...) = 'true') instead of equality (== or ===). In that line, you're also attempting to get the "checked" property of the string 'main_foc', which will be undefined.