Skip to content
github-actions[bot] edited this page Aug 12, 2026 · 5 revisions

Hooks are functions to call after some events happens. Defined with cr.hook() function.

Usage:

cr.hook("<event>", function(args...)

    -- some action

end)

Events

No return and no argument events

These events does not take any argument and does not return a value.

  • start: Runned before everything and main menu.
  • reload: Runned when plugins are reloaded.
  • draw: Runned after cr.draw_cards().
  • level_gen: Runned after cr.generate_levels()
  • after_refresh: Always runned after UI refresh.
  • before_refresh: Always runned before UI refresh.
  • game_start: When a new game starts.
  • game_end: When a game ends.
  • die: Runned when player dies.
  • ending: Runned when player finds Amulet of Yendor.

Has a return type or argument

These events takes arguments in varius types and may return a bool value.

key

Runned when a key pressed on main game loop.

No return type. Takes an integer argument: the key pressed.

Handle the key with string.char() and string.byte() functions, and cr.curses.KEY_ variables.

level_up

Runned when exit gate found.

No return type. Takes an integer argument: current level index.

slot

Runned when a slot picked.

Has bool return type: if true, slot will be skipped for now. Takes an integer argument: slots number (1, 2, 3)

item

Runned when user wants to use an item.

Has bool return type: if true, using item is canceled. Takes an shared card argument: the item used.

card_event

Runned when cr.basic_card_event called.

Has bool return type: if true, card event is canceled. Takes following arguments:

  • Shared card : the card
  • integer : extra damage value

Examples

-- show a log
cr.hook("start", function()
    cr.log("This log is added before everything")
end)

-- handle keyboard
cr.hook("key", function(key)
    if key == 27 then
        cr.log("pressed ESC")
    elseif key == cr.curses.BACKSPACE then
        cr.log("pressed backspace")
    elseif key == string.byte("a") then
        cr.log("pressed a")
    end
end)

-- disable cr.stat.slot1
cr.hook("slot", function(slot_id)
    if slot_id == 3 then
        return true
    end

    return false
end)
s_load & s_save

Runned after a save loaded (s_load) or created/updated (s_save).

No return type. Takes 1 string argument: save data as json.

Example save data:

{
    "_filepath": "/home/melon/.local/share/crogue/saves/7992049797823664169_1786440919.json",
    "created_with_plugins": {
        "test": "local",
        "vanilla": "https://codeberg.org/HasanAgitUnal/CROGUE-Vanilla.git"
    },
    "hp": 100,
    "inventory": [
        "vanilla:teleporter",
        "vanilla:apple",
        "vanilla:apple",
        "vanilla:apple",
        "vanilla:apple",
        null,
        null,
        null,
        null,
        null
    ],
    "last_played": 1786440919,
    "level": 1,
    "name": "No name",
    "plugins_changed": false,
    "seed": 7992049797823664169
}

Clone this wiki locally