Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Modifying and Creating Scripts

Much of the game’s logic is put inside of Luau scripts, for the sole purpose of being moddable and accessible to beginners!

Knowing how to script the game more deeply does depend on understanding Bevy’s ECS, but you can avoid learning all of that if you’re making small changes to existing code.

Picking a code editor

You really could use any text editor, but it’s better to use one with good Luau support for things like syntax highlighting and autocompletion.

I recommend either Zed or VSCode, both needing the Luau extension installed for the best development experience.

Setting up the Luau LSP in your code editor

NOTE: If you are working directly in the source code these files already exist. If you don’t know what this means, you likely aren’t working in the source code.

All editors:

  1. Create a file called .luaurc in the root directory of the game.
  2. Paste the contents of this file in it.

Zed-specific:

  1. Create a directory called .zed in the root directory of the game.
  2. Create a file called settings.json.
  3. Paste the contents of this settings file in it.

VSCode-specific:

  1. Create a directory called .vscode in the root directory of the game.
  2. Create a file called settings.json.
  3. Paste the contents of this settings file in it.

Neovim-specific:

Add the luau-lsp plugin and configure it like this:

vim.pack.add({
  {
    src = 'https://github.com/lopi-py/luau-lsp.nvim',
  },
})

require("luau-lsp").setup({
    platform = {
        type = "standard"
    },
    sourcemap = {
        enabled = false,
        autogenerate = false
    },
    types = {
        definition_files = {
            globalTypes = "assets/scripts/library/globalTypes.d.luau"
        }
    }
})

Basics

The easiest way to modify scripts is just by changing variables’ values!

To see this in action, open up assets/scripts/player.luau and go to the set_player_values() function.

Inside of this function, you can change the values of attributes given to the player, like acceleration and max speed.

-- a function that sets attributes of the player.
function set_player_values()
    local acceleration: MovementAcceleration = world.get_component(entity, MovementAcceleration)
    local max_speed: MaxLinearSpeed = world.get_component(entity, MaxLinearSpeed)

    -- set attributes
    acceleration[1] = 850.0
    max_speed[1] = 100.0
end

You can even do this while the game is open. Scripts are hot-reloadable, meaning changes are applied in the game the moment you save the file!