- Choosing an Editor
- gedit
- Installing gedit on Linux
- Installing TextWrangler on Mac OS
- First Steps with Your Editor
- Summary
First Steps with Your Editor
To get used to working with a programming editor, you’re going to create a new folder and file in the ScriptCraft plugins folder and save the new file.
Create a New Folder
In the File Browser pane (the Disk Browser in TextWrangler on Mac OS), locate and select the mcserver folder. Then navigate to the scriptcraft/plugins subfolder. Once that folder is selected, right-click the folder and choose New Folder from the menu (see FIGURE 4.11). Call your new folder learning for now. You can call it something else as long as it’s memorable—you’ll come back to this folder later.
FIGURE 4.11 Creating a new folder
Your new folder will now appear in the File/Disk Browser pane.
Create a New JavaScript File
The next step is to create a new JavaScript file in the subfolder you just created. The file won’t do much just yet, but you’ll work some more on it soon. Right-click the folder you just created and choose New File from the menu (see FIGURE 4.12). Call the new file helloWorld.js.
FIGURE 4.12 Creating a new file
The file has just been created but hasn’t been opened. If using TextWrangler, click the file to open it. If using gedit, double-click the file to open it. The file contents now appear in the editing pane on the right. The file is, as you’d expect, empty. Type in the following code exactly as you see it:
// TO DO : Add some code later
The previous code is just a comment you’ve added to remind yourself that you must add some proper code later. This comment isn’t understandable to the computer, so you can write whatever you like on a line beginning with //. The computer will not try to interpret and execute it. Comments like this can be useful for programmers because they make understanding code easier. Writing code is like any kind of writing—you should try to make your code readable by yourself and others, so if you look at your code later, you can figure out what you did.
Most programming languages provide a way to add comments. In JavaScript there are different ways you can add comments. You can add a single-line comment like the one shown previously by inserting two forward slashes (//), and then any text after is a comment and will be ignored by the computer until the next line. I’ll talk more about comments later in this book.
Saving Your Work
Save the file by choosing Save from the File menu or by pressing Ctrl+S (Cmd+S on Mac OS). The file is now saved. You can verify this by closing the file and opening it once more. To close the file, choose File > Close or click the close icon next to the filename at the top of the editor pane.
Reopen the file by double-clicking it in the File/Disk Browser pane. The text you entered previously should still be present. Saving your work is really important because code you edit will not take effect unless you first save it. You’d be surprised how often even experienced programmers forget this simple rule and are left wondering why their code isn’t working as expected.
When using ScriptCraft, the folder where you save your work is important. You can’t just save your files anywhere and hope they’ll be executed by ScriptCraft.
For now you’ve saved the newly created helloWorld.js file in the mcserver/scriptcraft/plugins/learning subfolder. Just as the Minecraft server looks for JAR files in its plugins subfolder to load Java-based plugins, ScriptCraft too looks for JS files in its own scriptcraft/plugins folder to load JavaScript-based plugins.