jsPsych/jspsych-call-function.js
Josh de Leeuw 691e8086ff call-func fix; added active-match
call-function: changed data storage so that if there was no return value
then no data would be stored in the data object. this helps when trying
to write data to a database as the empty data can be safely ignored.

active-match: new plugin for manipulating an image until it matches
another image.
2012-08-22 12:09:06 -04:00

44 lines
961 B
JavaScript

/** July 2012. Josh de Leeuw
This plugin gives the user the ability to execute an arbitrary function
during an experiment. It can be used to save data in the middle of an
experiment, for example.
Params:
"type" is "call_function"
"func" is the function that will be called
"args" is an array of arguments to pass to the function. (optional)
Data:
The return value of the function will be stored in the data.
**/
(function( $ ) {
jsPsych.call_function = (function(){
var plugin = {};
plugin.create = function(params) {
var trials = new Array(1);
trials[0] = {
"type": "call_function",
"func": params["func"],
"args": params["args"] || []
}
return trials;
}
plugin.trial = function($this, block, trial, part)
{
var return_val = trial.func.apply({}, [trial.args]);
if(return_val){
block.data[block.trial_idx] = return_val;
}
block.next();
}
return plugin;
})();
})(jQuery);