added variables option to jspsych-text

variables (in the form of functions) can be passed in to the text plug
in and their contents (return values) are substituted into the string
when the text plugin is displayed.

(also fixed bug in xab where correct/incorrect were backwards -- as of
jul 17 commit)
This commit is contained in:
Josh de Leeuw 2012-07-26 16:02:11 -04:00
parent 15cc690a9f
commit 4ea424b465
2 changed files with 55 additions and 40 deletions

View File

@ -13,12 +13,27 @@
trials[i]["text"] = params.text[i];
trials[i]["cont_key"] = params.cont_key;
trials[i]["timing"] = params.timing;
if(params.variables != undefined)
{
trials[i]["variables"] = params.variables[i];
}
}
return trials;
}
plugin.trial = function($this, block, trial, part) {
$this.html(trial.text);
var replaced_text = trial.text;
if(trial.variables != undefined)
{
for(var i = 0; i < trial.variables.length; i++)
{
var variable_text = trial.variables[i](); // variables are defined as functions
replaced_text = replaced_text.replace("%v", variable_text);
}
}
$this.html(replaced_text);
var key_listener = function(e) {
if(e.which==trial.cont_key)
{

View File

@ -72,14 +72,14 @@
var resp_func = function(e) {
var flag = false;
var correct = false;
if(e.which== trial.left_key) // 'p' key
if(e.which== trial.left_key) // 'q' key
{
flag = true;
if(!target_left) { correct = true; }
} else if(e.which== trial.right_key) // 'q' key
if(target_left) { correct = true; }
} else if(e.which== trial.right_key) // 'p' key
{
flag = true;
if(target_left){ correct = true; }
if(!target_left){ correct = true; }
}
if(flag)
{
@ -87,7 +87,7 @@
rt = (endTime-startTime);
stim1_time = (p2_time-p1_time);
isi_time = (p3_time-p2_time);
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "key_press": e.which, "stim1_time": stim1_time, "isi_time":isi_time}
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "stim1_time": stim1_time, "isi_time":isi_time}
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
$(document).unbind('keyup',resp_func);
$this.html(''); // remove all