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

September 24 (7 years ago)
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");
            }
    }
});
September 24 (7 years ago)
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 http://esprima.org/demo/validate.html. It will give a more useful error message (+ line number) than Roll20.
September 24 (7 years ago)
Thanks that helps.
September 24 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I also like the google closure compiler: https://closure-compiler.appspot.com/home
September 25 (7 years ago)
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 http://esprima.org/demo/validate.html. 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.