How To: Simple filters

This is a beginner tutorial for making simple player filters in LunaLua. These can be used to set the player character, or their power-up state.

To start with, let's look at the onStart function. This is an event you can put in your Lua file that runs when the level is loaded.

Powerup Filters
What we're going to do now is filter the player so that they are forced to be in the "big" state. We are going to be using the player.powerup field for this. One of the nice things about LunaLua is that lots of the values you need are stored as Constants. This means we don't need to worry too much about what the numbers are, but we can just set the powerup based on its name.

This will make force the player to be big when the level starts.

This works, but if the player starts the level with a fire flower, they will lose it when the level loads (because we're forcing them to be "big"). If we don't want this to happen, we need to check to see if the player has anything better, before forcing the player's state.

Now, the player will only be made big if they start the level small, which means they won't lose any hard-won powerups that they gained in other levels. You can also do this for other powerups. This code will give you a fire flower if you start a level small, or with just a mushroom:

Character Filters
Character filters are much the same as powerup filters.

This code will force the player to be Mario when the level starts.

The character codes are as follows:

As before, we can also do some tests, to set the character depending on other factors. Let's say we want, when the level starts, to set the character to Megaman if we choose Mario, Peach or Toad, and to Luigi if we choose anyone else. We can do that like this:

And that's it for this tutorial! There's a lot more you can do with LunaLua, but that's beyond the scope of this tutorial.