add time change

This commit is contained in:
minster586
2025-08-27 03:16:25 -04:00
parent 6283173263
commit 9920488a7c
2 changed files with 14 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ This OBS Studio Lua script writes your current stream uptime to a text file, wit
4. Click the `+` button and select `obs_uptime_to_file.lua`.
5. Set the `Output File Path` to where you want the uptime to be written.
6. (Optional) Set the `Format String` to customize how the uptime appears.
7. (Optional) Set the `Update Interval (seconds)` to control how often the file is updated (default: 1 second).
## Format String
You can control how the uptime is displayed using the `Format String` property. Use these placeholders:
@@ -32,7 +33,7 @@ You can control how the uptime is displayed using the `Format String` property.
- `{M} minutes``83 minutes`
## How It Works
- When you start streaming, the script begins writing the uptime to your chosen file every second.
- When you start streaming, the script begins writing the uptime to your chosen file at the interval you set (default: every second).
- When you stop streaming, the file is erased (emptied), so nothing will display if you use it as a text source.
## Use Case

View File

@@ -6,7 +6,8 @@ source_name = ""
output_path = ""
format_string = "{h}:{m}:{s}"
interval = 1000 -- ms
interval_sec = 1 -- seconds
interval = 1000 -- ms (default, will be set in script_update)
start_time = nil
hotkey_id = obs.OBS_INVALID_HOTKEY_ID
@@ -20,6 +21,8 @@ function script_properties()
obs.obs_properties_add_text(props, "format_string", "Format String", obs.OBS_TEXT_DEFAULT)
obs.obs_property_set_long_description(obs.obs_properties_get(props, "format_string"),
"Use {h} for hours, {m} for minutes, {s} for seconds. Example: {h}:{m}:{s}, {h}h {m}m, {m} minutes, etc.")
local interval_prop = obs.obs_properties_add_int(props, "interval_sec", "Update Interval (seconds)", 1, 60, 1)
obs.obs_property_set_long_description(interval_prop, "How often to update the file, in seconds (default: 1)")
return props
end
@@ -31,6 +34,9 @@ function script_update(settings)
else
format_string = "{h}:{m}:{s}"
end
interval_sec = obs.obs_data_get_int(settings, "interval_sec")
if interval_sec < 1 then interval_sec = 1 end
interval = interval_sec * 1000
end
function on_event(event)
@@ -42,6 +48,11 @@ function on_event(event)
erase_uptime_file()
start_time = nil
end
-- If timer is running, update interval
obs.timer_remove(update_uptime)
if start_time then
obs.timer_add(update_uptime, interval)
end
end
function update_uptime()