companion icon indicating copy to clipboard operation
companion copied to clipboard

Trigger on variable changed

Open BryanCrotaz opened this issue 2 years ago • 7 comments

Is this a feature relevant to companion itself, and not a module?

  • [X] I believe this to be a feature for companion, not a module

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the feature

There is an existing trigger for when a variable becomes equal to a value.

There is a missing case, where you want to trigger on a variable change, regardless of the value.

New trigger, Variable Change, which just takes the name of a variable, or an expression made of lots of variables

Usecases

Game scoring. Hold the score in a variable with buttons that increment/decrement it

Whenever the score changes, use an action via the Variable Changed trigger to send the new score to the display system (e.g. OBS) as a text update.

WIthout this feature you need to add the text update action everywhere that might change the score.

BryanCrotaz avatar Feb 13 '22 16:02 BryanCrotaz

I think that this needs some thought on how best to implement. I would prefer for it to be done as part of the 'feedbacks' triggers system, as I think it will be useful to be able to stack conditions (eg, you dont want it to run when you are playing out a clip), but I dont know how that will work. Perhaps it needs to be a 'pulse'?

This might be appropriate to move to https://github.com/bitfocus/companion-module-bitfocus-companion, depending on the concluded plan

Julusian avatar Feb 14 '22 00:02 Julusian

Maybe all triggers should have a list of ALL and NONE conditions. Only if all the ALLs and none of the NONEs are true does the trigger happen.

Should the trigger happen later?

Should triggers be on events of on state changes?

BryanCrotaz avatar Feb 14 '22 00:02 BryanCrotaz

That is a good point, the feedbacks are essentially state based and fire when entering the target state. (I think there is a request somewhere to also do things when leaving the target state). But the other types of triggers are essentially events that fire..

Perhaps we need to go back and rethink the triggers some more, to make the other types be events, with the feedbacks being used to 'filter' out events. Then this variable_changed would be one of those events, as well as an 'state_changed' event to handle the feedbacks changing

Julusian avatar Feb 14 '22 10:02 Julusian

A 'trigger' is an event. A trigger pull.

I think there are three types of event:

  1. A true event: button press, button release, change of state, startup etc
  2. A state entry
  3. A state exit

Each trigger can have a Condition which is OR List of conditions <ORed> OR List of conditions <ANDed>

This allows you to build any logic you need

A trigger in the UI could have multiple triggers with the same condition list

BryanCrotaz avatar Feb 14 '22 10:02 BryanCrotaz

Example

I want to set up device 1 with respect to device 2

Trigger on:

  • Device 1 enters online state
  • Device 2 enters online state
  • Device 2 feedback x changes

Conditions:

  • AND -- Device1 state = online -- Device2 state = online

Action: Device1 set my_state = device2 variable

BryanCrotaz avatar Feb 14 '22 10:02 BryanCrotaz

+1 for this trigger on variable changed 👍

gerbenvandekraats avatar Aug 16 '22 20:08 gerbenvandekraats

Use case: I have created an internal: Run shell path action that has a Target Variable (stdout) set. The command that is run outputs JSON which I would like to parse when the action completes and extract useful values from the JSON to assign to other variables that can be used to drive feedback.

eric avatar Sep 05 '22 01:09 eric

Any updates on this? I have a use case:

I need to send OSC message to a software with a number corresponding to a variable. There are a number of ways this variable can be changed, so it won't do any good having the trigger check a specific button or other variable to send the message. It's currently doable by creating a trigger for each possible variable value, but as you can imagine this stacks up fast. Additionally, there seems to be no way to reorder triggers either, so it turns into a giant pile of mess very fast (maybe I should create a request for that too). If there was a function to trigger when variable changes, then I could have a single trigger that would send an OSC message with the variable being a part of the address/path every time the variable changes

Velikyi avatar Nov 02 '22 03:11 Velikyi

This will be possible in v3.0. Its still a little way off (v2.4 is coming first) See #2165 for info on the complete change

Julusian avatar Nov 08 '22 20:11 Julusian

This is in the 3.0 betas

Julusian avatar Dec 06 '22 21:12 Julusian