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

[Bug?] Why is the API text editor adding spaces at the beginning of my lines, and how do I stop it?

1485834607
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I was not sure whether this should be put in the bugs section or here, but I figured I would start here. I am working on an API script. I noticed that for some reason my code was way off to the right with lots of spaces/tabs in front of every line of code/comments. So I went through the entire (very long) file and deleted an average of 4 tabs of whitespace until everything was lined up where I wanted it.  A while later I noticed that it had shifted right again! Not as far as it had been, but it had shifted! So I went in and changed a few lines of code to exactly where I want it.      var Startup = function() {         'use strict';          init();          registerAPI();     }; So for example for this routine, I very carefully deleted all whitespace from the front of every line, then put one tab in front of the first and last line, and two tabs in front of the interior lines. Everything was done in the roll20 API editor (IE: I did not copy it into notepad or anywhere else then paste it back). I then saved it, exited, and reentered the editor. The code now looks like this!           var Startup = function() {               'use strict';                init();                registerAPI();           }; There is now an extra tab and two spaces in front of every line! IE: the interior lines have 3 tabs and 2 spaces! What is going on here?
1485834860
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
As a followup, occasionally it does not add whitespace to a line, this causes the code to not only not be formatted as I want, but to have certain lines to have less indenting than needed for clear understanding. This whole thing is very annoying. 
1485839711
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Huh, I haven't encountered this in the whole time I've been scripting. First thing to check I suppose would be do you have any extensions installed that might change how something looks?
1485850436
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Nether have I. I have scripting on roll20 for 18 months or so, and this is the first time I have seen this.  However I can now duplicate it as will. It only seems to happen when the first line of the file is blank.      // one     // two     //three      var Test = (function() { }); In the above, the first two lines are blank. If you save and exit, then reenter, there is only one blank line and everything has been shifted over 6 spaces. If you resave it and exit and enter again, there are no blank lines, the first line "// one" is now with no spaces in front of it but every other line has 6 additional spaces in front of it.  A few weeks ago I got an error message and I tracked it down to the fact that the ending  close comment marker */  in my first script was appended directly to my 2nd scripts starting comment marker  /* which gave a /**/ that the system did not like. I put a blank line as the first and last line of both scripts.  Now I find that both scripts have the blank line removed, the first line of the comment is flush to the left edge, and most other lines in the script have a tab and two spaces inserted.  It seems that you need to have a space as your first character (to avoid the first character of the first line of your 2nd script being appended directly to the last character of the last line of your first script), but it can't be a blank line else wierdness happens. 
1485924635
Lucian
Pro
API Scripter
Hey Chris, This probably isn't the answer you're looking for, but: I'd strongly recommend using a "real" text editor outside of Roll20 to edit your scripts. Ideally use a JS-aware editor that gives you the ability to reformat/find references/refactor automatically etc. I lost an enormous amount of work through careless mistakes with the script editor before finally setting myself to edit scripts in a proper IDE (you don't need to go that far though). The cost of doing Ctrl-A Ctrl-C Alt-tab Ctrl-A Ctrl-V every so often is far outweighed by the benefits it brings. For example, IntelliJ, which I use, let's me define exactly how I want my code laid out, and then I just need to hit Ctrl-Alt-L and it reformats everything automatically. Intellij is a heavyweight option, but there are plenty of other simpler (and cheaper/free) options out there. I know one of my co-authors on the Shaped Companion used the free OSS MS editor VS Code with great success, for example. The roll20 script editor is fine for editing things a few dozen lines long, but as soon as you start editing something sizeable it's not really up to the job. Cheers,
1485926310
Lithl
Pro
Sheet Author
API Scripter
I wasn't aware IntelliJ had a JavaScript-compatible editor. I used it years ago for Java. These days, I mostly use Eclipse as my editor simply because its modularity lets me use it for whatever I need (especially integration with version control systems!)
1485947508
Lucian
Pro
API Scripter
Brian said: I wasn't aware IntelliJ had a JavaScript-compatible editor. I used it years ago for Java. These days, I mostly use Eclipse as my editor simply because its modularity lets me use it for whatever I need (especially integration with version control systems!) Jetbrains (who make Intellij) do IDEs for just about every major programming language. Intellij IDEA Ultimate is their flagship platform that lets you incorporate most of the features of their language-specific IDEs into a single IDE, much as you can do in Eclipse. It also has plugins for just about any tool you're likely to want to use - VCS, build systems etc. I switched from Eclipse because I was fed up with the slowness, the bugs, and the lack of properly joined-up-thinking in how all the tools integrated together. That was a few years ago, perhaps it's better now.
1486088102
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ok, now I am seeing this, but I don't have any empty lines at the top of my script (unless you count comments).