"delay()" statement does not work inside function "OnSignalTrigger"

Hello,

I try to put a delay(10.0) statement inside the function OnSignalTrigger() to delay the execution of the script of a bool signal map. But the ‘delay()’ statement is skipped.

I try to put delay() in OnRun() function, the statement works. Does this mean that delay() only effective inside OnRun() function?

Yes, it is by design so each script can only have one “paused” execution state. It would get complicated if you would have e.g. multiple OnSignal method calls running in parallel within a script.

Thank you for your reply.

Is there a way to schedule executing some statements in Visual Components? Such as, let a signal to be sent after 10 sec?

Thank you!

You can add delays in OnRun(), and use triggerCondition to wait for signal triggers.
Example:

from vcScript import *


def OnRun():
  while True:
    triggerCondition(lambda: getTrigger() == signal1 and signal1.Value)
    print("delaying for 10 seconds")
    delay(10.0)
    signal2.signal(True)

comp = getComponent()
signal1 = comp.findBehaviour("BooleanSignal")
signal2 = comp.findBehaviour("BooleanSignal_2")
1 Like