Skip to content

Commit

Permalink
Add response collection option
Browse files Browse the repository at this point in the history
Record RT since the appearance of the sequence item.
  • Loading branch information
jodeleeuw committed May 1, 2014
1 parent 7d5738a commit e8b11ed
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions plugins/jspsych-vsl-animate-occlusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
trials[0].image_size = params.image_size || [100, 100];
trials[0].initial_direction = params.initial_direction || "left";
trials[0].occlude_center = (typeof params.occlude_center === 'undefined') ? true : params.occlude_center;
trials[0].choices = params.choices || [32]; // spacebar
// timing
trials[0].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial;
trials[0].timing_pre_movement = (typeof params.timing_pre_movement === 'undefined') ? 500 : params.timing_pre_movement;
//trials[0].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt;
Expand All @@ -52,7 +54,11 @@
// if any trial variables are functions
// this evaluates the function and replaces
// it with the output of the function
trial = jsPsych.normalizeTrialVariables(trial);
//trial = jsPsych.normalizeTrialVariables(trial);

// variable to keep track of timing info and responses
var start_time = 0;
var responses = [];

var directions = [
[{
Expand Down Expand Up @@ -104,6 +110,8 @@
src: i
});

// start timer for this trial
start_time = (new Date()).getTime();
}
}

Expand All @@ -123,6 +131,20 @@
fill: "#000"
});
}

// add key listener
var resp_func = function(e){
for(var i=0; i<trial.choices.length; i++){
if(e.which == trial.choices[i]){
responses.push({
key: e.which,
stimulus: which_image - 1,
rt: (new Date()).getTime() - start_time
});
}
}
};
$(document).keydown(resp_func);

if (trial.timing_pre_movement > 0) {
setTimeout(function() {
Expand All @@ -137,10 +159,13 @@

display_element.html('');

$(document).unbind('keydown', resp_func);

block.writeData($.extend({}, {
"trial_type": "vsl-animate-occlusion",
"trial_index": block.trial_idx,
"stimuli": JSON.stringify(trial.stims)
"stimuli": JSON.stringify(trial.stims),
"responses": JSON.stringify(responses)
}, trial.data));

if (trial.timing_post_trial > 0) {
Expand Down

0 comments on commit e8b11ed

Please sign in to comment.