Skip to content

Instantly share code, notes, and snippets.

@acuifex
Last active February 27, 2024 22:12
Show Gist options
  • Save acuifex/bf9092b2bdbc1894e1a0b4171c7b3f8f to your computer and use it in GitHub Desktop.
Save acuifex/bf9092b2bdbc1894e1a0b4171c7b3f8f to your computer and use it in GitHub Desktop.
Example of communication between OBS scripts/plugins.
# State of this module actually persists between script deletions.
# I think it's loaded the first time it's imported,
# and is kept until OBS shutdown or until OBS somehow deinitializes python.
# You'll probably have to reload this module to reset its state.
# https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module
globalcount = 0
def print_global(who):
print(who, globalcount)
def add_to_global(who, count):
global globalcount
print(who)
globalcount += count
import obspython as obs
import examplelib
def print_val(props, prop):
examplelib.print_global("script1")
def add_val(props, prop):
examplelib.add_to_global("script1", 2)
def script_properties():
props = obs.obs_properties_create()
obs.obs_properties_add_button(props, "printbtn", "print", print_val)
obs.obs_properties_add_button(props, "addbtn", "add 2", add_val)
return props
import obspython as obs
import examplelib
def print_val(props, prop):
examplelib.print_global("script2")
def add_val(props, prop):
examplelib.add_to_global("script2", 3)
def script_properties():
props = obs.obs_properties_create()
obs.obs_properties_add_button(props, "printbtn", "print", print_val)
obs.obs_properties_add_button(props, "addbtn", "add 3", add_val)
return props
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment