The PI tasks expose one central object that serves as the hub of all of you tasks.
The [task objects][../current] 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 (current) as well.
window.piGlobal.greeting = 'Hello world';
console.log(window.piGlobal);
There are several properties within global
that have a special meaning.
The global.$meta
variable has a special meaning within the player.
Each time the logger triggers within any of the manager tasks, all the data with then global.$meta
object is added to each row of the log.
The following definition will cause each log posted to the server to include uid
:
API.addGlobal({
$meta: {uid: '12345678'}
});
The global.$postOnce
variable is posted to the server immidiately at the start of the task sequence.
Note that any changes to this variable during the sequence will have no effect.
The following definition will cause the condition
to be saved to the server at the begining of the session.
API.addGlobal({
$postOnce: {condition: 'long'}
});
The query string is a set of parameters that can be passed within a URL string.
The global object exposes the url query string in a dedicated object called $url
.
So that if you have a url such as example.com?bar=buz&bam=bif
the object takes the following form:
global.$url == {
bar: 'buz',
bam: 'bif'
}