How to consume time in simulation
vcCore uses asyncio module. This requires the use of "async" and "await" naming when consuming simulation time.
Wait for a signal or property value
Time consuming function, like OnRun() always requires "async" before the name. This also applies to any user-defined functions that consumes time.
Method that consume simulation time — like delay() and waitFor() must be called with "await".
import vcCore as vc async def OnRun(): comp = vc.getComponent() sensor_signal = comp.findBehavior("SensorSignal") while True: await sensor_signal.waitFor(True, waitTrigger = True) await vc.delay(5) # do something
Wait for a condition to be true
Use the condition() method to wait until a specific condition is met.
This is useful when you want to wait for multiple signals or properties to reach a certain state.
import vcCore as vc async def OnRun(): comp = vc.getComponent() sensor_signal = comp.findBehavior("SensorSignal") sensor_signal2 = comp.findBehavior("SensorSignal2") while True: await vc.condition(lambda trigger: sensor_signal.Value == True and sensor_signal2.Value == True) await vc.delay(5) # do something
Note: the "trigger" argument refers to the object that triggered the evaluation of the condition(). You can also manually trigger evaluation by calling evaluateConditions().