Skip to content

Tutorial 4.5 (Common pitfalls)

Aerll edited this page Dec 27, 2023 · 1 revision

Example 1 - No rotation only

As we already know, in r++ there is a difference between no rotation and a rotation N, which represents no rotation. Sometimes we may need to check for N and intuitively we write:

Insert(0).If(
    IndexAt([0, 0]).Is(1)
);

Then we run such automapper, and it turns out that it removes all tiles 1 instead of just 1 with no rotation. This happens a lot, so always remember to use .N:

Insert(0).If(
    IndexAt([0, 0]).Is(1.N)
);

Example 2 - Borders with overriding

We've already seen this one in the part about overriding, but we'll go through it again. This problem occurs, when we test for a specific tile. Let's say we have the following rule:

NewRun();
Insert(1, 2, 3).If(
    IndexAt([0, 0]).IsWall(top).TestIndices(g:mask)
).Roll();

This may seem correct, but it's not. Even though we don't enable overriding anywhere, this will create vertical stripes all over our mask. We need to remember, that Roll enables overriding automatically, it simply needs it to work properly. We can fix this, by splitting it into 2 runs:

NewRun();
Insert(254).If( // places another mask only where the top wall tiles are located
    IndexAt([0, 0]).IsWall(top).TestIndices(g:mask)
);

NewRun();
Insert(1, 2, 3).If( // rolls tiles on our mask
    IndexAt([0, 0]).Is(254)
).Roll();

Example 3 - Borders on empty tiles

This is another problem with borders, which occurs when we test for empty tiles. Let's say we have a rule like this:

Insert(1).If(
    IndexAt([0, 0]).IsWall(top).TestIndices(0)
);

Now empty tiles behave like full tiles and vice versa. Everything seems to be alright, so where's the catch? For some reason automapper places our tile on the top edge of the map. Why is that? Simply because automapper treats a tile outside of the map as a non-empty tile, which means, the edge of the map is now also a border. To fix this, we need to be more specific:

Insert(1).If(
    IndexAt([0, 0]).IsWall(top).IsNotEdge(top).TestIndices(0)
);