getTrigger() doesnt seem to work

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.

Any help is appreciated. Thanks

The trigger will not persist, so once it happens the pointer is cleared. Immediately after your triggerCondition(), add and test this:

signal = getTrigger()

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.

Hi,

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:

  1. When 2 sections is moved out
  2. 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?

from vcScript import *

comp = getComponent()
node = comp.findNode(“Link_1”)
node = comp.findNode(“Link_2”)
node = comp.findNode(“Link_3”)
node = comp.findNode(“Link_4”)

servo = comp.findBehaviour(‘ServoController’)
node.Dof.Controller = servo

rise_signal = comp.findBehaviour(‘rise_signal’)
rise_signal_2 = comp.findBehaviour(‘rise_signal_2’)

TASKS = []
def OnSignal(signal):
if signal.Name == “rise_signal”:
TASKS.append(RiseUp)
elif signal.Name == “rise_signal_2”:
TASKS.append(RiseUpTwo)

def OnRun():
del TASKS[:]
condition(lambda:TASKS)
TASK = TASKS.pop(0)
TASK()

def RiseUp():
servo.move(375, 0, 0, 0)
servo.move(375*2, 375, 0, 0)

def RiseUpTwo():
servo.move(375, 0, 0, 0)
servo.move(3752, 375, 0, 0)
servo.move(375
3, 3752, 375, 0)
servo.move(375
4, 3753, 3752,375)