在 OBS 中改进 countdown.lua,使倒计时结束时更换场景

我已经找出了如何在 countdown.lua 中添加并填充场景选择下拉菜单,也知道在哪里放置切换场景的代码。但我如何使用 lua 在 OBS 中切换场景呢?被选中的目标场景在下拉菜单中称为 next_scene

function set_time_text()
    ...
    if cur_seconds < 1 then
        --# BJS 跳转到在“next_scene”字段中存储的场景中
    end
...
function script_properties
...
    local t = obs.obs_properties_add_list(props, "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
点赞
用户4213836
用户4213836
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
    end

set_time_text() 函数的实现如上所示。当 cur_seconds 的值小于 1 时,会执行一系列操作。如果 next_scene 不为空并且不等于字符串 "-----",则会获取对应的场景资源,并将其设为当前场景。否则会将 text 的值设为 stop_text

2020-08-16 16:13:36