Writing Minecraft Plugins in JavaScript: Choosing and Using a Text Editor
Up to now you’ve been executing JavaScript at the server console window using the js command. This is a perfectly good way to try JavaScript. It’s nice to have a command-line interpreter when trying things out and exploring a new language. However, once you want to start doing some real work with JavaScript, you’ll want to be able to save your work and run it, without issuing many js commands at the server console window each time your server starts.
FIGURE 4.1 JavaScript code in an editor with no syntax highlighting
FIGURE 4.2 JavaScript code in an editor with syntax highlighting turned on
ScriptCraft lets you load JavaScript files you’ve saved and either can run them automatically when the server starts up or can run your code on-demand. If you plan on saving your work, you’ll need to write your code using a text editor. Any text editor could do, but I strongly recommend using a text editor dedicated to programming. A programming text editor will have a few extra bells and whistles to make writing code easier than it would be in a plain old text editor like Note-pad. Most programming editors have what’s called syntax highlighting, which colors different parts of your code to make it easier to read. Compare FIGURE 4.1 from a regular text editor to FIGURE 4.2 from a programming editor.
I think you’ll agree that the syntax highlighting in FIGURE 4.2 makes the code more pleasant to read.
Choosing an Editor
There are many programming editors to choose from. Which editor you choose is ultimately up to you. I’ve been using Emacs—an open source editor—for many years, but I don’t recommend it to beginning programmers because, while powerful, it takes some time to learn. Programmers get very attached to their programming editors after time. You should start with an editor that’s easy to use and learn. In this chapter, I’ll talk about gedit, but you can use any of the following programming editors to get started programming:
- Notepad++ is a free editor for Windows you can download at http://notepad-plus-plus.org/.
- TextWrangler from BareBones Software is a free editor for Mac OS X you can download at http://www.barebones.com/products/textwrangler/.
- Sublime Text is a cross-platform editor that you can evaluate for free for as long as you like. You can download Sublime at http://www.sublimetext.com/.
Let’s get started installing gedit. You can skip this section if you’ve already installed and use a programming editor on your computer. Mac OS users can skip the following section and go straight to “Installing TextWrangler on Mac OS.”