MULTIBOXING

How to use #Include

Make your scripts shorter, simpler, and easier to maintain.

#Include is extremely useful. It makes scripts simpler, shorter, and easier to write.

I didn’t invent it. It’s a standard part of programming languages.

Oops, I shouldn’t have told you that, because now you’ll think it’s technical and complicated.

Actually it’s such a simple thing that I feel a little silly writing an article about it. But although it’s very simple, it’s hard to explain without showing an example. So I wrote this article to give you an example.

“#Include” means “copy and paste.” It’s a way of telling Mojo, “copy and paste that other script into this script.” Scripts are files, and I’ll use the two words interchangeably.

Suppose you play five different teams, and each one needs a slightly different script. I say slightly different because many hotkeys are the same in all of them. For example, all the scripts contain the following hotkey.

Hotkey (F1)
{
    ToggleHotkeys()
}

That hotkey is just one example of many hotkeys that all five scripts share in common. You could of course copy and paste those shared hotkeys repeatedly, putting copies of them in every script. But what happens next month when you decide you want to change one of those shared hotkeys? You’ll have to change five copies of it! What a pain in the ass. Wouldn’t it be better if you had only one copy, so you only need to change it once? That’s what #Include does for you. It allows you to write each shared hotkey only a single time. Here’s how you use it.

Write those shared hotkeys in a separate file by themselves. You can call that file anything you want. I’ll call it “common.txt” because the contents are common to or shared by all the scripts. Now, in each of the five scripts, write this single line:

#include common.txt

You have to write that at the start of a line. If the file name contains spaces, you have to put in quotation marks.

When Mojo loads the script, it will see that line and at that point in the script, it will copy and paste the contents of common.txt into the script. You won’t see the copy and pasting because it takes place in Mojo’s memory, not on the hard disk. Your files that you saved on your hard disk don’t change. Only Mojo’s internal copy of the file changes.

That’s the whole idea. I hope it’s clear.

You can include as many files as you want, and a file that you include can itself include files. In other words, a file can include a file, and that second file can include a third file, and that third file can include a fourth, and so on. Programmers call this nesting. It’s like matryoshka dolls.

Keep #Include in mind, and I think you’ll find many ways to use it to make your scripts shorter, simpler, and easier to maintain.

For technical details about #Include, see #Include.

Related

#Include

This page was first published on January 22, 2018 and last modified on January 22, 2018