Search code examples
luaobs

Improve countdown.lua in OBS to change scenes when timer complete


I figured out how to add and populate a dropdown of scenes in countdown.lua, and I see where to put the code that would switch scenes. How do I changes scenes in OBS using lua? The dropdown with the chosen destination scene is called next_scene.

function set_time_text()
    ...
    if cur_seconds < 1 then
        --# BJS goto scene stored in field "next_scene"
    end
...
function script_properties
...
    local t = obs.obs_properties_add_list(props, "next_scene", "Next Scene", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING)
    local scenes = obs.obs_frontend_get_scene_names()
    if scenes ~= nil then
        for _, scene in ipairs(scenes) do
            obs.obs_property_list_add_string(t, scene, scene)
        end
    end

Solution

  • function set_time_text()
            ....
            if cur_seconds < 1 then
            if next_scene ~= "" and next_scene ~= "-----" then
                local source = obs.obs_get_source_by_name(next_scene)
                obs.obs_source_release(source)
                obs.obs_frontend_set_current_scene(source)
            else
                text = stop_text
            end
        end