Skip to content

Using a Timer for Experiment

There are a few ways you can set up your experiment to run on a timer. Perhaps the easiest would be to use the start and end conditions in the GUI. You can set the first trial to wait for a signal to start (such as Custom Event- triggerPress or Key Press - SPACEBAR), then set the timer for all trials to use End- Timer  and choose number of seconds to run. Each subsequent trial could use a Start- Timer to choose how long of a cooldown you want between trials. 

To see another method of setting this up with code see the ExampleScript\Timer. This uses yield viztask.waitTime()

import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *

sightlab = sl.SightLab(gui = False)
sightlab.setTrialCount(2)

env = vizfx.addChild('sightlab_resources/environments/complete_scene.osgb')
sightlab.setEnvironment(env)

import viztask
def sightLabExperiment():
    yield viztask.waitEvent(EXPERIMENT_START)
    while True:
        yield sightlab.startTrial(condition = [KEY_PRESS,' '])
        yield viztask.waitTime(3)

        yield sightlab.endTrial()
        yield viztask.waitTime(2)
viztask.schedule(sightlab.runExperiment)
viztask.schedule(sightLabExperiment)