Vizard 8 » Tutorials & Examples » Designing an experimental study » Tutorial: Creating the experiment framework
8.1

Tutorial: Create the experiment framework

Most experiments consist of various phases. In order to break these phases up into their logical pieces and control the flow of your program from one phase to another task functions are extremely helpful. Tasks (created with the viztask module) control the order of events by pausing and waiting for specific conditions to be met, like a key press or an action to end, before they proceed. In this way, when one phase of the experiment is done, another can be set in motion.

 

Our experiment will have the following phases:

First we'll take this information and build a framework for our script using viztask. After that we'll go through these phases one by one and add the code to make each one a working component.

Building the program framework

The following code takes our outline from above and translates it into the main viztask function (i.e. experiment). As you can see, the flow of the program is easy to read. Each phase is contained within a subtask function (i.e. participantInfo, learnPhase, testPhase). Both participantInfo and testPhase return data that will be saved to a text file.

def experiment():

    #Wait for spacebar to begin experiment
    yield viztask.waitKeyDown(' ')

    #Proceed through experiment phases
    participant = yield participantInfo()
    yield learnPhase()
    results = yield testPhase()

viztask.schedule(experiment)

Next, definitions for each subtask are added. Place the following code at the end of your script. The pass statements are placeholders we'll soon replace with code to make each subtask a functional component of the program.

def participantInfo():
    pass

def learnPhase():
    pass

def testPhase():
    pass

def experiment():

    #Wait for spacebar to begin experiment
    yield viztask.waitKeyDown(' ')

    #Proceed through experiment phases
    participant = yield participantInfo()
    yield learnPhase()
    results = yield testPhase()

viztask.schedule(experiment)

Loading the virtual environment

Creating the experiment framework

Entering participant data

Learning phase of experiment

Testing phase of experiment