diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 2300fd9db..cdb149f6f 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -77,7 +77,12 @@ function messpect(...) end ---@return nil function register_console_command(name, cmd) end ---Returns unique id for the callback to be used in [clear_callback](https://spelunky-fyi.github.io/overlunky/#clear_callback). You can also return `false` from your function to clear the callback. ----Add per level callback function to be called every `frames` engine frames. Timer is paused on pause and cleared on level transition. +---Add per level callback function to be called every `frames` engine frames +---Ex. frames = 100 - will call the function on 100th frame from this point. This might differ in the exact timing of first frame depending as in what part of the frame you call this function +---or even be one frame off if called right before the time_level variable is updated +---If you require precise timing, choose the start of your interval in one of those safe callbacks: +---The SCREEN callbacks: from ON.LOGO to ON.ONLINE_LOBBY or custom callbacks ON.FRAME, ON.SCREEN, ON.START, ON.LOADING, ON.RESET, ON.POST_UPDATE +---Timer is paused on pause and cleared on level transition. ---@param cb function ---@param frames integer ---@return CallbackId diff --git a/docs/src/includes/_globals.md b/docs/src/includes/_globals.md index 6a32219e7..8f97e451a 100644 --- a/docs/src/includes/_globals.md +++ b/docs/src/includes/_globals.md @@ -250,7 +250,12 @@ end, 60) #### [CallbackId](#Aliases) set_interval(function cb, int frames) Returns unique id for the callback to be used in [clear_callback](#clear_callback). You can also return `false` from your function to clear the callback. -Add per level callback function to be called every `frames` engine frames. Timer is paused on pause and cleared on level transition. +Add per level callback function to be called every `frames` engine frames +Ex. frames = 100 - will call the function on 100th frame from this point. This might differ in the exact timing of first frame depending as in what part of the frame you call this function +or even be one frame off if called right before the time_level variable is updated +If you require precise timing, choose the start of your interval in one of those safe callbacks: +The [SCREEN](#SCREEN) callbacks: from [ON](#ON).LOGO to [ON](#ON).ONLINE_LOBBY or custom callbacks [ON](#ON).FRAME, [ON](#ON).[SCREEN](#SCREEN), [ON](#ON).START, [ON](#ON).LOADING, [ON](#ON).RESET, [ON](#ON).POST_UPDATE +Timer is paused on pause and cleared on level transition. ### set_on_player_instagib diff --git a/src/game_api/script/lua_vm.cpp b/src/game_api/script/lua_vm.cpp index acbad8b46..9fa37f53b 100644 --- a/src/game_api/script/lua_vm.cpp +++ b/src/game_api/script/lua_vm.cpp @@ -435,7 +435,12 @@ end }; /// Returns unique id for the callback to be used in [clear_callback](#clear_callback). You can also return `false` from your function to clear the callback. - /// Add per level callback function to be called every `frames` engine frames. Timer is paused on pause and cleared on level transition. + /// Add per level callback function to be called every `frames` engine frames + /// Ex. frames = 100 - will call the function on 100th frame from this point. This might differ in the exact timing of first frame depending as in what part of the frame you call this function + /// or even be one frame off if called right before the time_level variable is updated + /// If you require precise timing, choose the start of your interval in one of those safe callbacks: + /// The SCREEN callbacks: from ON.LOGO to ON.ONLINE_LOBBY or custom callbacks ON.FRAME, ON.SCREEN, ON.START, ON.LOADING, ON.RESET, ON.POST_UPDATE + /// Timer is paused on pause and cleared on level transition. lua["set_interval"] = [](sol::function cb, int frames) -> CallbackId { auto backend = LuaBackend::get_calling_backend();