Skip to content
WarmUpTill edited this page Mar 21, 2024 · 6 revisions

Variables

Variables allow users to simplify complex macro setups.
They each have a name and a value, which can be checked using the Variable condition and modified using the Variable action.

Variables can also be used in scene selections or scene item selections in place of scenes or sources.
In this case the value of the variable will be used to find the corresponding scene or source.

Creating a new variable

A new variable can be added to a Variable condition or action by clicking on the "Add new variable" entry in the variable selection menu.

AddVar

When selecting this entry a dialog will open in which you will have to enter the variable properties:

VarProps

  • Unique name for this new variable (1).
  • The current value of the variable (2).
  • What to do with the current value when closing OBS: (3)
    • Don't save it, resulting in the value to be empty when restarting OBS. (a)
    • Saving it, resulting in the current value to be restored when restarting OBS. (b)
    • Setting it to a different value on OBS restart. (c)

VarSave

Modifying existing variables

VarProp

To modify the properties of an existing variable simply select it in the drop down menu of a variable action or condition and click the marked gear symbol. Next click the "Properties" entry and a dialog like described above will open in which you can modify the variable's settings.

The gear icon will also allow you to rename or remove existing variable.

Variable condition

VarCond

The Variable condition will allow you to test for various properties of the value of a given variable.
It supports checking if the variable ...

  • equals a given value.
  • is empty.
  • equals a given number.
  • is less / greater than a given number.
  • has changed.
  • and more ...

Variable action

VarAction

The Variable action will allow you to modify the value of a given variable in various ways.
It supports ...

  • setting the value of a variable.
  • appending to the value of a variable.
  • appending the value of another variable.
  • in-/ decrement the value of a given variable. (Assuming it is a valid number)
  • and more ...

Using variables

  • Variables can be used in scene, scene item, and source selections of various actions and conditions.

    ExampleVar

  • Variables can be used in the text fields of various conditions and actions:

    ExampleVar3

    The syntax to use variable in those text fields is ${variable name here}.

  • Variables can be used in most number based selections, e.g. duration or area selections.

    DurationVariable

    The default value will be 0.0 if a given variable is not a valid number.

Example "Podcast"

The following example is intended to showcase how to set up macros to automatically switch scenes in a podcast setting, with scenes focusing on a single person in case only single person is speaking and a separate scene in case multiple people are speaking at the same time.

The example will use the Variable "Next Scene" to indicate which scene the advanced scene switcher will switch to at the end of the check interval.

Setup

The following setup is assumed:

  • Three audio input sources named "Guest 1 mic", "Guest 2 mic", and "Host mic".
  • Four scenes are created named "Guest 1 scene", "Guest 2 scene", "Host scene", and "Wide scene". The first three represent a scene focusing on the guests or host respectively and the last one is used when more than one person is speaking at a time.

Macros

Three macros are created to set the variable "Next scene" to the respective scene if only a single person is speaking.

This is achieved by using an audio condition (1) to check the volume of the particular audio source and then setting the variable to the desired value using a variable action (2).
Optionally one can add a duration modifier (3) to make sure the scenes are not switched to frequently.

G1

Similarly, the other two macros are created using different sources and values for the variable.

G2

H

To handle the case of multiple people speaking at the same time we use the "Macro" condition in combination with the option to check the states of other macros.
In case of more than one of the other macros being true we set the variable to the name of the wide scene.

W

Finally, we add a macro that does the scene switching.
To avoid unnecessary scene switches we choose to only run this macro if the value of the variable changed using the variable condition.

SS

Note that it is recommended that the macro switching the scene is below the macros setting the value for the "Next Scene" variable.
Otherwise, the value of the previous interval will be used, which might lead to undesired effects.

Without the use of a variable one would have to repeatedly add condition checks to make sure a scene switch did not already happen to avoid rapidly switching between in the same interval.

Example "Set variable to text source text"

This example shows how to extract the text displayed by a text source into a variable named "Text Source Text".

The condition "Source" is used to assign the settings to the Text Source Text variable initially using the "Set to condition value" variable action. The value of the condition itself does not matter as it is combined with "Or" and "Plugin is running" which is always true.

Next two "Set to substring of current value" variable actions are used to extract the "text" value of the text source's settings.

TextSourceToVariable

Example "Set up variables containing date / time data"

You can set up a helper macro like this to populate variables with the current date and time:

1707002475935

You can import this example using this code:

AAAVXnic7VhbbyI3FP4rlp/abaAMm220vG2zRIu0aVDIpqqqqDIzhxmLwR7ZHhYa8d97jj03GnVLSx4HgTT+zsXn8tmD/cw3Ijba8snvz1yJDfAJX4BjH4UD9iiMFMscLL/ghSgtClcit0AjI/Ic8gbQ6joTKm017FoW0x3Ed2rhhHENnhpdFs0o0fEap3NSpRjCMzeQSuvANAqZsPel+rl0Tis+caYM2JyieYHiTK60n8WyE1gm0yzHn5utrrVKpJNa2Qe0aDRM7f8Bdhgnx/nqfI9wPydKSvVS9iVgKI2PJgkRVUrt/EwYYBT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