Helper script

Hi, I can’t help with one script. I have a script that will show me (box) when it receives a signal. Could you advise me how I can change this script to do the opposite logic. That is when I get a signal the given object (box) disappears.
Thank you for your help

from vcScript import *
comp = getComponent()
signal = comp.findBehaviour(‘Bool’)
def OnSignal( signal ):
pass

def OnRun():
comp.Visible = False
while True:
triggerCondition(lambda:getTrigger()==signal )
comp.Visible = signal.Value
comp.rebuild()
def showBox(simulation, isRunning):
if isRunning:
comp.Visible = signal.Value
else:
comp.Visible = False

app = getApplication()
sim = app.Simulation
sim.OnStartStop = showBox

This code looks like it should be the one I gave you in the first place, the point of this code is that when the simulation environment starts, OnStartStop is triggered to first set the visibility of the cube to Signal.Value (which would normally be False), and at that point OnRun, because of the triggerCondition() function, is hung up waiting for the signal signal value change, when the signal is sent, because the hang condition is only one signal value change, so whether it is True or False will stop the hanging state of OnRun and set the visibility of the component comp to signal.Value, which means that the whole fluent will be:
Simulation start → component visibility off → wait for signal → signal triggered to give value to component visibility → next wait
You can just change comp.Visible = signal.Value to comp.Visible = not signal.Value if what you want is to assign the visibility value to the opposite value when the signal arrives.
If you have other needs, you can always ask. :melting_face:

1 Like

Hey, Bad. So I managed to change the program and it’s working for me now. Thank you for your help

Well, I’m glad it helped you to some extent. :melting_face: