Variables
- Core
- Sequencer
- Inheritance
- Mixers
- Variables & Templates
Sometimes it is not enough to hard code behaviors into your tasks, sometimes you want behavior to depend on a previous response, or change some texts according to randomization. In order to achieve these behaviors you can use variables.
We will first describe variables that are common across all tasks, and are always available - these are the global
and current
variables.
Then we will get down to variables variables that are available only in specific contexts - such as the data
and meta
variables.
Accessing variables
There are many ways to use variables within the PI tasks. You can learn about them in their respective documentation, check out conditions and templates. In addition, some of the variables can be accessed directly from your JavaScript, in cases that this is possible it will be mentioned in the description of the variable.
Global
The PI tasks expose one central object that serves as the hub of all of you tasks.
The task objects get automatically registered on the global
object, so that you can access them all from here.
In addition, you can register any data that you want shared between your tasks onto global
.
This options is useful in various cases of branching, as well as when you want a common theme to appear in multiple tasks.
The following snippet sets global.value
to 123, and global.variable
to [1,2,3].
API.addGlobal({
value: 123,
variable: [1,2,3]
})
It may sometimes be handy to access global
directly as window.piGlobal
.
Note that this allows you to access task objects as well.
window.piGlobal.greeting = 'Hello world';
console.log(window.piGlobal);
The task object (current)
Each PI task creates an object that holds information regarding that task.
The object is automatically updated with data from within the tasks (such as question answers or other logs).
The task object can be changed manually as well.
You can extend it however you like using API.addCurrent
:
API.addCurrent({
value: 123,
variable: [1,2,3]
});
While a task is running, its task object is available as current
.
Even when the task is not active it is available from within the global
object, as global.<taskName>
,
where <taskName>
stands for the task name as defined within the task manager.
For your convenience, here is a table describing some of the data available within the different task objects.
Task | Description |
---|---|
miTime | The task object holds all trial logs: current.logs . |
miQuest | The task object holds all questions: current.questions . |
Local Variables (local & meta)
The variables that we've discussed so far are relevant for whole tasks or even whole studies. We now approach variables that have a narrower scope: they have to do with specific elements within your task. These variables are called Data and Meta.
The Data variables allow you to manually set useful information into each element. Their behaviour is described fully within as part of element inheritance.
The Meta variables hold some meta information regarding this element that is auto-generated by the mixer. In particular it holds two properties: `
Property | Description |
---|---|
number | The serial number for this element within the sequence (i.e. 3 if this is the third element to be presented). |
outOf | An attempt to estimate how many elements are in the sequence overall. This number cannot be fully trusted as the number of elements may be dynamically generated and depend on various variables not yet determined. |
The naming convention for these variables is <elementName>Data
and <elementName>Meta
respectively.
For example, for tasks they appear as tasksData
and tasksMeta
.
The elementNames for the various tasks are as follows:
Task | elementName | Object names |
---|---|---|
miManager | tasks | tasksData, tasksMeta |
miQuest | pages | pagesData, pagesMeta |
questions | questionsData, questionsMeta | |
miTime | trial | trialData, trialMeta |
stimulus | stimulusData, stimulusMeta | |
media | mediaData, mediaMeta |
License: Apache 2. © Project Implicit. · Current version [version]