Add examples of lua and python external script files

The Static Mage 2025-09-14 13:36:39 -05:00
parent 6e2641b384
commit d4a5ce7f5f

@ -37,6 +37,58 @@ def script_load(settings):
Each script will be assigned a unique `id`.
Whenever the signal `advss_run_temp_script` is emitted by the plugin each script will check if the `id` emitted with this signal matches its id and execute the `run` function if applicable.
### Inline script examples (Script type = File)
When you use Script type = File to define your script within a file, that script file must:
- Have the appropriate extension (`.lua` or `.py`)
- Include the OBS scripting runtime as `obs`
- Define the `script_load` function to invoke the script when the "id" equals the full path to the script
LUA example (replace `/tmp/advss-example-script.lua` with the actual path to your script):
```lua
obs = obslua
function run()
obs.script_log(obs.LOG_WARNING, "Hello from LUA!")
return true
end
-- AUTO GENERATED --
function script_load(settings)
local run_wrapper = (function(data)
local id = obs.calldata_string(data, "id")
if id == "/tmp/advss-example-script.lua" then
local ret = run()
obs.calldata_set_bool(data, "result", ret)
end
end)
local sh = obs.obs_get_signal_handler()
obs.signal_handler_connect(sh, "advss_run_temp_script" , run_wrapper)
end
```
Python example (replace `/tmp/advss-example-script.py` with the actual path to your script):
```python
import obspython as obs
def run():
obs.script_log(obs.LOG_WARNING, "Hello from Python!")
return True
## AUTO GENERATED ##
def script_load(settings):
def run_wrapper(data):
id = obs.calldata_string(data, "id")
if id == "/tmp/advss-example-script.py":
ret = run()
obs.calldata_set_bool(data, "result", ret)
sh = obs.obs_get_signal_handler()
obs.signal_handler_connect(sh, "advss_run_temp_script", run_wrapper)
```
## Custom macro condition
This examples shows how to register a new condition type which will randomly evaluate to `true` based on provided user input percentage in the range from 0 to 100.