Tutorial 1 (First automapper) - Aerll/rpp GitHub Wiki

About automappers

The way automappers work is similar to the way we read (left to right and top to bottom). Imagine however, that you're reading each letter separately and that you've been told to change every letter a to b. This is essentially what automappers do.

r++ allows us to tell the automapper what to change, and when.

Setting up

The very first line of every automapper will look like this:

#include "base.r"

base.r is a file, which defines a whole bunch of useful instructions for the automapper. To be able to use them, first we need to import them and #include does exactly that. It grabs the file we specified inside the quotes "" and pastes its content in that line.

Note: r++ uses paths relative to the directory, from which you're running the program.

Next we will set the output path and a full name of the generated file:

#output "Pandora's Box\generic_unhookable.rules"

Note: only .rules extension is accepted. In case when there's no extension, the program will automatically append it.

This line tells the program to generate a file called generic_unhookable.rules inside Pandora's Box directory. Note that the directory has to exist. By default it is set to tileset.rules.

There's one last setting, which deserves to be mentioned:

#memory "100"

This tells the program, how many MBs of memory it is allowed to use. By default it is set to 50, which is more than enough for most automappers.

Creating an automapper

Now that everything is set and ready, we can dive into the actual code. We will create our first automapper, which is going to clear every tile from the map.

In r++, every automapper has to follow a certain order, otherwise the program will throw an error. Before we can create any rules, first we need to create a new automapper and give it some name. This name is going to be displayed in the editor. We do this by writing:

AutoMapper("Sweeper");

Note: r++ is case sensitive: Automapper is not the same as AutoMapper.

It's worth noting, that every line of code in r++ ends with ;. There are some exceptions to this, but we will cover them in another tutorial.

Creating a run

Next step after creating an automapper, is creating a new run. This is what makes the automapper traverse through all of the tiles, one by one.

To create a new run, we write:

NewRun();

Additionally r++ comes with a feature, which allows you to create multiple copies of the run:

NewRun(3); // 3 copies

Creating a rule

Next up are rules. This is the fuel for automappers. With rules we can tell the automapper what to place, and under what conditions.

In our case, we want the automapper to clear every tile from the map, therefore, we need to replace all of them with an empty tile. We can do this by simply writing:

Insert(0);

This line tells the automapper to insert a tile 0, which stands for an empty tile.

Comments

In r++ we can write comments, which are ignored by the program. We have a choice between single line and multi line comments.

To write a single line comment we precede it with //:

// ignored text

To write a multi line comment we enclose it with /* and */:

/*
   ignored
   text
*/

Generating

To generate rules from r++ code, simply drag and drop your file onto rpp.exe. Make sure that base.r is in the same directory as your automapper.

You can also run the program from a command line:

rpp.exe "relative_path" [-p]
  • "relative_path" - relative path to a file containing r++ code
  • -p - optional switch to disable pausing

Full code

#include "base.r"
#output "generic_unhookable.rules"

AutoMapper("Sweeper");
NewRun();

Insert(0);
⚠️ **GitHub.com Fallback** ⚠️