Skip to main content

The last thing we need to do before we start writing mods is discuss what software to use to write the mods. Any plain text editor would work, but I'd recommend using something designed for writing code, as you'll have extra features, such as auto indentation, and syntax highlighting that you won't get in most plain text editors. Be careful not to use anything that saves extra formatting, such a bolds or italics, as that will mess up the code.

Throughout this course I'll be using Atom, an open source text editor created by the team at Github. Atom is a bit on the heavy side, and may not be suitable for everybody. Not to worry though, although I'll be using a few extra features of Atom that most other editors don't have, don't feel as though you have to use Atom. If you are already familiar with another code editor keep using that. I'll be using a linter in Atom, that many other editors probably don't have, but not to worry, Minetest will give you information about errors in code when trying to launch a mod if it has mistakes, and I'll show how to use the information Minetest provides to debug the code.

Over the years I've used a handful of different editors, and can recommend the following for Linux, Mac, and Windows: Geany, and Jedit. Notepad++ is a good option as well, but is only available on Windows. These are all opensource softwares, but doubtless there are many decent closed source options as well. I'll reiterate, If you've already coded in an editor, and like how it works, there is likely no reason to change to another editor for this course.

If you are going to use Atom let's take a look at some of the packages I've installed, otherwise feel free to skip the rest of this lesson.

I won't cover how to install Atom, because there is nothing special to that, just visit http://atom.io and download the appropriate installer and then install. Once you have Atom installed launch it and open the settings with Ctrl + Comma or by using the edit>preferences. I'm using the One Dark UI Theme and Syntax Theme, because I think the dark colors are easier on the eyes, but feel free to use different, just know that your text may be shown in different colors than mine.

Lets install some packages to take full use of Atom's power, starting with language-lua, which will give us syntax highlighting while working on code. Secondly lets install a linter, which will help us discover errors in our code, before we try running the code in Minetest. The linter is actually two parts, we need to install linter and then linter-lua so the linter engine knows what the check syntax wise. I've made a change to the linter, 'cause the default values annoyed me. I changed the Lint on Change Interval to 6000 ms from the default 300, as I don't see the need for the checks to be run that often. When Linter finds an error it will put a red dot at the line in code where the problem is detected. The status bar will also be updated, and clicking on the Linter button we can get more information about the error. I'll demo this more when we get to coding, though hopefully I won't be making that many errors. :)

Last thing to do is change a few editor settings. I've changed my font size to 23, just to make sure that the text is easily readable at lower resolutions, feel free to leave this at the default 14 though. I changed the Preferred Line Length to 90, as the Minetest code guidelines call for lines to be kept lower than 90 characters long. This just places a faint line in the editor to show where the limit is. You can make lines longer than that, but you should try not to. I changed the Tab Length to three from two, which just makes the indentations one space deeper. The last change was Tab Type which I switched to soft rather than auto, as I always want to use spaces as tabs, rather than tabs as tabs.

I'll give a quick overview of Atom before we finish. On the left side of the window you'll see a project panel, (If you don't see one place your cursor near the left edge of the window and a little half circle button with an arrow should appear, click on that arrow to open the side panel.) you can add entire mod folders here, or single files. When we get to writing mods with multiple files it's really nice to be able to add the entire mod in one step and be able to navigate between files with very little effort. To add a project folder you can either right-click in the window and select the Add Project Folder, or using the menu. File>Add Project Folder or if you want to add a single file you can use File>Open File. When using project folders we're able to create new files directly within atom by simple right clicking and selecting New File.