Custom Keybinds

Keybinds are important. They're the things that let you actually play the game. Kristal has a lot of bindings, from player movement to debug features.

However, what if you wanted to add your own keybind? Like, say, a dance button?

Registering a Keybind

To register a keybind, you must create a keybinds section in your mod's (or library's) mod.json/lib.json, and populate it with the keys you'd like to have in your mod/library.

For example, this is a dancing keybind:

{
    "keybinds": [
        {
            "name": "Dance",
            "id": "dance",
            "keys": ["a"],
            "gamepad": ["gamepad:leftshoulder"]
        }
    ]
}

It should look something like this:

Keys should be lowercase, and gamepad buttons should be one of the buttons listed here, prefixed with gamepad:.

Additionally, lsup, lsdown, lsleft, and lsright are the left stick directions, and rsup, rsdown, rsleft, and rsright are the right stick directions. lefttrigger and righttrigger are the left and right triggers.

Using the Keybind

Using the new custom keybind is like using any other keybind in Kristal.

You can use the Input class to check if the keybind is pressed:

if Input:down("dance") then
    Game.world.player:setAnimation("dancing")
end

Or if you're using a callback, check if the pressed key is the dance key:

function Mod:onKeyPressed(key)
    if Input.is("dance", key) then
        Game.world.player:setAnimation("dancing")
    end
end