Skip to content

Laboratory of Neuropsychology

Creating a Task

The best way to learn how to write your own task is to begin with an existing example and try modifying it. There are many example tasks under the "task" folder of the NIMH MonkeyLogic installation directory.

Conditions File & Timing Script

NIMH MonkeyLogic supports the original MonkeyLogic's behavioral tasks, so a new task can be written in the traditional style using a conditions file and a timing script (runtime library version 1). The conditions file is a tab-delimited text file which lists a set of stimuli that can occur in each trial. Each stimulus is referred to as a "TaskObject" and can take the form of a visual object, a sound, or an analog or TTL output. The timing script is a MATLAB program that determines when and under what conditions each of those stimuli is presented. For the stucture of those files and how to write them, please refer to the conditions file manual and the timing script manual.

In NIMH ML, the conditions file and the runtime v1 script can be replaced with the userloop and the runtime v2 script, respectively.

Userloop Function

The conditions file requires defining all trial conditions explicitly. This can be inconvenient sometimes, for example, when there are so many conditions and stimuli or when the task needs a flexible way of randomizing trial sequences and handling error trials. A userloop function is a MATLAB function that feeds the information necessary to run the next trial, in lieu of the conditions file. It is called before each trial starts and allows user to determine the condition of the next trial on the fly. You can also preload large stimuli in the userloop function and reuse them so that the inter-trial interval does not get increased by the stimulus creation time. The details of the userloop function are well-documented in the example tasks that are under the "task\userloop" directory of the NIMH MonkeyLogic installation folder.

New Runtime Library (V2)

In the previous set of timing file functions (or runtime library v1), stimulus presentation and behavior tracking were handled by toggleobject() and eyejoytrack(), respectively. This framework is a bit disadvantageous in designing dynamic, interactive stimuli, because stimuli and behavior are processed separately and there is no proper way to change stimuli during behavior tracking. NIMH MonkeyLogic provides another way to compose tasks which uses "adapters" as building blocks of task scenes and two new functions, create_scene() and run_scene(), that replace toggleobject() and eyejoytrack(). Please refer to the runtime library version 2 manual and the timing script manual for the details. Many examples of the runtime library v2 scripts are in the "task\runtime v2" directory.