Lua script property with OBS_TEXT_INFO not updating properly

strauburn

New Member
I'm writing a Lua script and attempting to add an informational text label to my script properties using a text property with the text type "OBS_TEXT_INFO", which I think is fairly new (maybe added in v28?). The property add looks like this:
Lua:
local p_info_text = obs.obs_properties_add_text(props, "info_text", "Testing info:", obs.OBS_TEXT_INFO)

I want to be able to update the text in the property periodically based on current status (e.g. update it from a timer callback), but I'm having trouble getting the script properties to actually refresh to show the new text.

I set a modified callback for the text info property and return true, which is supposed to trigger a refresh when that callback is called.

Just changing the text in the settings (using a global variable holding the current settings) doesn't actually trigger the callback.

Changing the text followed by a call to obs_properties_apply_settings(props, settings) -- again, using global variables for the props and settings -- does cause the text's callback to get called, but the script properties still don't refresh like they're supposed to. Also, for some reason this seems to have the side effect of causing OBS to crash if I select a different script in the scripts window while this is running.

If after the text has been (invisibly) changed, the user manually refreshes the script property screen by selecting a different script and then selecting this one again, the text does show the new value. Also if the script property screen get refreshed by another means, like a different property getting updated and triggering a refresh, that also refreshes the info text to show the new value.

Here's a simple full example script demonstrating what I'm talking about. The example just has a "Start" button that starts a counter. The counter is supposed to update the info text with the current count once a second, but it's not working.
Lua:
obs           = obslua

test_cnt = 0
function count_timer()
    test_cnt = test_cnt + 1
    obs.obs_data_set_string(cur_settings, "info_text", tostring(test_cnt))
   
    -- Adding the line below has no actual effect on updating the properties, even though
    -- it does trigger calls to info_text_modified_cb. But it also causes OBS to crash if I
    --  switch selection to another script and try to switch back.
    --obs.obs_properties_apply_settings(global_props, cur_settings)
end

function info_text_modified_cb(props, p, settings)
    print("info_text_modified_cb called")
    return true
end

is_counting = false
function start_counting(props, p)
    if not is_counting then
        is_counting = true
        obs.timer_add(count_timer, 1000)
    end
    return true
end

function script_properties()
    local props = obs.obs_properties_create()
    local p_info_text = obs.obs_properties_add_text(props, "info_text", "Testing info:", obs.OBS_TEXT_INFO)
    obs.obs_property_set_modified_callback(p_info_text, info_text_modified_cb)
    local p_start_btn = obs.obs_properties_add_button(props, "start_btn", "Start", start_counting)
    global_props = props
   
    obs.obs_properties_apply_settings(props, cur_settings)
    return props
end

function script_description()
    return "Test script for testing OBS_TEXT_INFO text properties."
end

function script_update(settings)
    cur_settings = settings
end

function script_defaults(settings)
    obs.obs_data_set_default_string(settings, "info_text", "Default text")
end

function script_save(settings)
end

function script_load(settings)
    -- only good way I could figure out how to make it load with default text instead of last saved text:
    obs.obs_data_set_string(settings, "info_text", obs.obs_data_get_default_string(settings, "info_text"))
end

Am I doing something wrong, or is the API bugged? Let me know if you've got any suggestions. It seems like it would be a nice way to show info to the script user, but if I can't get the property to refresh, then it's not really useful.

I am using the latest OBS version, which right now is v28.0.3, and running on Windows.

Lastly, note that I've only tried this in Lua. I have no clue if the corresponding Python or C++ API has the same issue or not.
 
Last edited:

honganqi

New Member
Hi. I tried out your script and got it to work only by changing obs.OBS_TEXT_INFO in line 30 to obs.OBS_TEXT_DEFAULT since the former enum type was causing errors:
Failed to call script_properties for obs_lua_script_get_properties: C:/temp/OBS text sources/scripts/test.lua:30: Error in obs_properties_add_text (arg 4), expected 'enum obs_text_type' got 'nil'
By "work", I mean I can see the text box changing to the test_cnt variable everytime I press "Start".

--=EDIT=--
I'm still using OBS 27.2.3
 
Top