triggerCondition() does not work for BoolSignalMap

I try to write script for a component in modeling.

The component has several ports connected to the other components.

signal = comp.findBehaviour("signal")
signal_map = comp.findBehaviour("signal_map")

def foo(signal_map, port, value):
  return value

signal_map.OnSignalTrigger = foo

In the OnRun() function, the following part works for a signal

triggerCondition(lambda: signal.Value == True)

For signal map, the following part does not work

triggerCondition(lambda: signal_map.OnSignalTrigger == True)

My question is: is my way of implementing triggerCondition() on signal map wrong?

Thank you!

I try the following changes and works

First, change the function def to:

def foo(signal_map, port, value):
  return signal_map

Then change the lambda expression to:

triggerCondition(lambda: signal_map.OnSignalTrigger != None)

triggerCondition only evaluates the condition on very specific limited cases, it is not a magical “observe and re-evaluate whenever this arbitrary lambda’s return value might have changed” system.

I think triggerCondition is re-evaluated when any signal which is connected to the script behavior (and thus also causes a OnSignal call) is triggered, not sure if there any other cases.

Thank you for the answer!

Now I also remembered that there is a evaluateCondition() method which can be used to trigger re-evaluation of an active triggerCondition within the script’s OnRun method. It can be useful when a script is listening to events other than signals.

1 Like