I am creating a Component. I have created two (boolean) signals for it, “TurnTable” and “Door”
I then try to trigger functions based on the trigerred signasl but it doenst work
from vcScript import *
comp = getComponent()
turn_signal = comp.findBehaviour("Turn_Table")#prints <vcBoolSignal object>
door_signal = comp.findBehaviour("Door") #prints <vcBoolSignal object>
def OnRun():
while True:
triggerCondition(lambda: getTrigger()==door_signal or getTrigger()==turn_signal)
print "Something Trigerred" #prints "Something Trigerred"
print getTrigger() #prints "None"
if getTrigger()==turn_signal:
TurnTable() #doesnt execute
if getTrigger()==door_signal:
Door(door_signal.Value) #doesnt execute
From the print statement (Something Trigerred) its clear that the tiggerCondition() works as needed
However, the getTrigger() works only in the lambda function (Otherwise it wouldnt have printed Something trigerred). The two if statements fail as getTrigger() gets the value “None” and doest execute functions TurnTable() and Door(). Also goes without saying that I have the python script as connections to the signals or else the lambda functions wouldnt return True
What could I be possibly doing wrong? I use VC premium 4.1 on a windows 10 PC.
Hi, thanks for the reply, but if this is what you meant it doesn’t work.
def OnRun():
while True:
triggerCondition(lambda: getTrigger()==door_signal or getTrigger()==turn_signal)
signal = getTrigger()
print "Something Trigerred" #prints "Something Trigerred"
print signal #still prints "None"
if signal==turn_signal:
TurnTable() #doesnt execute
if signal==door_signal:
Door(door_signal.Value) #doesnt execute
Hi, as you pointed out that the trigger didnt persist, it caused me to think in that perspective and I came up with this which works.
def OnRun():
while True:
triggerCondition(assignTrigger)
#signal = getTrigger()
print "Something Trigerred" #prints "Something Trigerred"
print signal #prints <signal>
if signal==turn_signal:
TurnTable() #executes
if signal==door_signal:
Door(door_signal.Value) #executes
def assignTrigger():
global signal
signal= getTrigger()
return signal
However, I would still like to know why the previous approach didnt work.
What you’ve build is actual a standard function in VC, it is called the OnSignal() function. The OnSignal function is being called once a signal triggers the script.
See below for a short example code that you can use, haven’t tested it but I think it should work.
def Turn():
print "turning"
def Door():
print "Door something"
tasks = []
def OnSignal(signal):
if signal.Name == "TurnSignal":
tasks.append(Turn)
elif signal.Name == "DoorSignal":
tasks.append(Door)
def OnRun():
del tasks[:] # start with an empty tasks list
while True:
condition(lambda: tasks)
task = tasks.pop(0)
task()
Hi!
This script works! I have checked.
But I have other question…Now I am animating the telescopic pillar and I have 2 positions:
When 2 sections is moved out
When 4 sections is moved out
But position 2 must be should be a continuation of the second. The pillar continue to move out after 2 sections.
Now it doesn’t work correctly.
Please, could you help me?