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

If an API .js file ends ina // comment, it generates error message: SyntaxError: Illegal return statement

1523069975
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
OK, so I just wasted some hours finding a weird bug and it's workaround, which I am documenting here so that others might be able to google the solution.  My .js scripts started generating an error message  Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: SyntaxError: Illegal return statement So I started deleting routines one by one, starting with the most recently updated, then starting at the top and eventually doing all of them . It did not go away until I deleted the line that said });    // End ON Chat:message. Which was the very last line of 5600 line file!  Further experimentation found that if I delete the comment, but leave the brace, paren, semi-colon.  Or if I leave everything, but put at least one blank line after it, everything is OK.  It is only when the very last line has a // comment on it that you get the "Illegal return statement" error.  So make sure you always have a blank line as the last line of your .js file. I had years previously found that if the first character of your .js file was not a space, you also have problems. 
All different scripts that you install for a campaign are concatenated into one large file when the sandbox spins up. So if your last line ends with a comment and without an additional line break, it will be joined with the first line of the next script, essentially commenting out that line. Therefore, it's a good practice to add one or two blank lines at the end of your scripts.
1523251344
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Agreed, that is the problem. And that is the user work-around to the problem, and I agree it is good practice to do that.  Another solution would be for the system to concatenate all the scripts with an automatically generated line-break between them so the first line of the 2nd script is not considered by the parser to be on the same line as the last line of the first script.  Having the parser consider the first line of each script to be upon the same line as the last line of the previous script is a bug. The existence of a simple work-around does not change the fact that it is a bug.  Specifically my point is that the system is concatenating them incorrectly and it would be a fairly trivial fix the system to concatenate them correctly, by simply putting a line break between each file.  Having these bug reports documented and google-able work arounds are important. as it allows scripts to work until the developers fix their bugs. But having a documented work-around is not a substitute for the developers fixing their bugs.