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 Lua scripts, for the sole purpose of being moddable!

Knowing how to script the game correctly does depend on understanding Bevy’s ECS, but you can avoid 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 Lua support for things like syntax highlighting and autocompletion.

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

Basics

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

To see this in action, open up assets/scripts/player.lua 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()
    ---@type MovementAcceleration
    local acceleration = world.get_component(entity, MovementAcceleration)
    ---@type MaxLinearSpeed
    local max_speed = world.get_component(entity, MaxLinearSpeed)

    -- set attributes
    acceleration[1] = 850.0 -- change this!
    max_speed[1] = 100.0 -- change this!
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!