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

Need help on why my scripts are failing to load. Also, Best ways to begin and end API scripts to avoid interfering with other API scripts.

1574589556

Edited 1574590024
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I am trying to figure out why both of the API scripts that I have submitted to Github to the API library fail to load correctly, when both work fine if just pasted into the API screen. Again, if they are pasted into the API screen, they work fine. But if you to to the Script Library and select them, they fail (I will explain how they fail further below).&nbsp; I suspect&nbsp;it might have to do with how I begin and end my API scripts.&nbsp; Roll20 API just seems to concatenate scripts into one long file. However I have noticed that things such as comments and spaces in one script can affect how the next script is interpreted.&nbsp; For example: If one script ends with a comment such as "// end of whatever", then it will treat the first line of the following script as a comment. So rule number one, don't end an API script with a // comment.&nbsp; Years ago I also found troubles if the last line of an API was a /* */ comment, and the first line of the following API was ether an /* */ comment or an // comment. Apparently it was seeing /* *//* */ or /* */// and it was messing up, but I just&nbsp;tested both of those just now, and there does not seem to be any problems, so maybe that got fixed in the last few years.&nbsp; Anyway, I notice that many scripts just seem to begin with a // comment, and the last line just seems to end with a function call without a comment, such as&nbsp; }); &nbsp; All well and good, and I assume that works very well as long as nobody does anything that messes things up.&nbsp; However due to some weird things that I was seeing several years ago, my API's all start with a blank line, then a space, then I do my first // comment.&nbsp; At the end of my file, I always had two blank lines.&nbsp; These work fine if just pasted into the API screen, but I do notice that what I do is different that what anybody else is doing, and wonder if somehow my having blank lines at the beginning and end of my file are what is messing things up. I am pretty sure I am going to resubmit my scripts without the blank lines and spaces and see what that does, but I wonder if anybody has any tips (or horror stories) about how to put your code and comments so as not to mess up any previous or subsequent scripts.&nbsp; OK, here are the specific ways in which my scripts are messing up.&nbsp; Earthdawn by FASA character sheet companion If this script is pasted into an API box, there are no errors. If you go to the Script Library and import it, there are no errors. But if you go to the Script Library and Add it, it says&nbsp; 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.&nbsp; More info... For reference, the error message generated was:&nbsp; SyntaxError: Invalid or unexpected token Let me just repeat that. If you add the script, you get an error. If you Import the exact same script from the library, it works fine!&nbsp; &nbsp;This is obviously a bug in Roll20, but when I submitted a bug report they moved it to this subforum. A message to <a href="mailto:team@roll20.net" rel="nofollow">team@roll20.net</a> did not get any help. Duplicate and add identifying number to Character and Token &nbsp;&nbsp; Also known as DupCharToken: Again, if you just paste the .js into an API screen and save it, it works fine.&nbsp; But if you go to Script Library, and try to Add or Import it, it just silently fails. It does not give any error message as to why it failed. It does not even give any indication that it did fail. It just proceeds to the next screen without having actually added or imported the .js.&nbsp; And I have no clue as to why it is failing. And like I said, if you just paste the .js in by hand, everything works fine. So anyway, I have checked all the obvious things, and am left checking for maybe it dislikes there being blank lines or spaces at the beginning or ends of files. Any help anybody could give as to what it likes to see, or what in the past has caused it to silently fail to load me would be greatly appreciated.&nbsp;
1574595169
GiGs
Pro
Sheet Author
API Scripter
I dont have an answer for you, but now that you mention it, I remember seeing the dupchartoken issue raised on the forums before, maybe more than once, and I think it's shocking that the roll20 devs have done nothing to help you figure out what's going on.
1574641999
The Aaron
Roll20 Production Team
API Scripter
I brought up the concatenation of scripts problems 4–5 years ago, but no love yet.&nbsp; Beginning with a comment is my standard practice. You could begin with a ; just to close off any prior scripts.&nbsp; I'll have to try those two from the script library. Do they fail if they are each the only installed script?
1574643758
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Excellent question, I should have thought of that myself.&nbsp; The dupCharToken script still fails to load even if it is the only script.&nbsp; The Earthdawn by FASA companion script seems to be loading now, but it does not appear to run.&nbsp; I might be having the same problem right now as the other guy who posted a few hours ago about the API console not working.&nbsp;
1574645224
The Aaron
Roll20 Production Team
API Scripter
Interesting. Then it's unlikely to be a problem with other scripts and more likely some sort of encoding issue. I assume having the script library copy the script into the game works fine, but if it doesn't, it might be an interesting data point.&nbsp;
1574654067

Edited 1574654100
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Well once again, with the Earthdawn by FASA sheet companion, If you import the script from the library, it works fine. If you Add the script from the library, it says it found an invalid or unexpected token. I was considering the possibility that the problem was that it started off with blank lines, then a line that starts with a space.&nbsp; What are your thoughts on encoding issues? Notepad++ is saying that DupCharToken is encoded as UTF-8, for when I just paste it into the API screen. Earthdawn as UTF-8-BOM It uses some extended characters. But it seems OK in github.