Support Home Scripting Use Cases Data Saving

Data Saving

In Gorilla, you can save participants' data, such as their responses or accuracy scores, in the Store. Each piece of data that you save in the Store will be saved in a named field, so that you can retrieve it and use it later in the task, game, or experiment.

There are several readily available save-to-store components in the Screen Components menu, which simply store specified data to a designated field, e.g. a Save Accuracy component saves response accuracy to a chosen field. However, you might wish to customise the data saving to e.g. manipulate stored data by adding some values to it. You can achieve this by creating your own data saver.


Start by creating a new component with the Screen Component template:

New script panel showing the Screen Component template selected and the name MyScorer in the name box

You can now implement your logic in the construct() and screenFinish() lifecycle methods:

// in your component body public construct() { this.sourceBinding = this.createBinding(); this.destBinding = this.createBinding(); super.construct(); } public apply(f: CustomDataSaverFactory) { this.sourceBinding.parseIfExists(f.source); this.destBinding.parseIfExists(f.destination); } public screenFinish() { super.screenFinish(); // at the end of the screen, we read in the source, do something with it // and then write it to the destination let val = parseInt(this.sourceBinding.value); if(!isNaN(val)) { // write your custom data saving logic here this.destBinding.write(val); } } private sourceBinding: Binding; private destBinding: Binding;

Note that, for the destination binding, you'll want to use a specific form element to tell Gorilla that you want to bind to a destination, not a source:

// when registering your component //------------------------------------------------------------------------------ registerEditor('MyDataSaver', { label: 'My Data Saver', icon: 'fas fa-backpack', form: { elements: [ { class: "FormElementBindableText", label: "Source", field: "source" }, { class: "FormElementBindableField", label: "Destination", field: "destination" } ] } }) //------------------------------------------------------------------------------

Scripting Sample

For a worked example of a new data saving component see our Custom Data Saving Example.