mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
added options to si-kr plugin
can now opt to leave the stimulus on the screen for a fixed length of time, still recording the responses when they occur. also allows a timelimit to be set on the responses, so that if no responses is recorded after some period of time, the trial completes and records a -1 as the response.
This commit is contained in:
parent
a08dbc7029
commit
42d78b3510
@ -18,8 +18,11 @@
|
||||
trials[i]["type"] = "singleimage_keyresponse";
|
||||
trials[i]["a_path"] = stims[i];
|
||||
trials[i]["choices"] = params["choices"];
|
||||
// option to show image for fixed time interval, ignoring key responses
|
||||
trials[i]["continue_afer_response"] = params["continue_after_response"] || true;
|
||||
// timing parameters
|
||||
trials[i]["timing_stim"] = params["timing_stim"]; // if undefined, then show indefinitely
|
||||
trials[i]["timing_stim"] = params["timing_stim"] || -1; // if -1, then show indefinitely
|
||||
trials[i]["timing_response"] = params["timing_response"] || -1; // if -1, then wait for response forever
|
||||
trials[i]["timing_post_trial"] = params["timing_post_trial"] || 1000;
|
||||
// optional parameters
|
||||
if(params["prompt"] != undefined){
|
||||
@ -33,25 +36,34 @@
|
||||
}
|
||||
|
||||
var sikr_trial_complete = false;
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
|
||||
plugin.trial = function(display_element, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
key_press = -1;
|
||||
sikr_trial_complete = false;
|
||||
|
||||
startTime = (new Date()).getTime();
|
||||
$this.append($('<img>', {
|
||||
display_element.append($('<img>', {
|
||||
"src": trial.a_path,
|
||||
"id": 'sikr_img'
|
||||
}));
|
||||
|
||||
//show prompt here
|
||||
if(trial.prompt != undefined){
|
||||
$this.append(trial.prompt);
|
||||
display_element.append(trial.prompt);
|
||||
}
|
||||
|
||||
var cont_function = function(){
|
||||
endTime = (new Date()).getTime();
|
||||
rt = (endTime-startTime);
|
||||
sikr_trial_complete = true;
|
||||
plugin.trial(display_element, block, trial, part+1);
|
||||
}
|
||||
|
||||
// hide image if timing is set
|
||||
if(trial.timing_stim != undefined){
|
||||
if(trial.timing_stim > 0){
|
||||
setTimeout(function(){
|
||||
if(!sikr_trial_complete){
|
||||
$('#sikr_img').css('visibility','hidden');
|
||||
@ -71,18 +83,40 @@
|
||||
}
|
||||
if(flag)
|
||||
{
|
||||
endTime = (new Date()).getTime();
|
||||
rt = (endTime-startTime);
|
||||
key_press = e.which;
|
||||
|
||||
var trial_data = {"rt": rt, "a_path": trial.a_path, "key_press": e.which}
|
||||
// after a valid response, the image will have the CSS class 'responded'
|
||||
// which can be used to provide visual feedback that a response was recorded
|
||||
$("#sikr_img").addClass('responded');
|
||||
|
||||
if(trial.continue_after_response){
|
||||
// response triggers the next trial in this case.
|
||||
// if hide_image_after_response is true, then next
|
||||
// trial should be triggered by timeout function below.
|
||||
cont_function();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(document).keyup(resp_func);
|
||||
|
||||
// end trial if time limit is set
|
||||
if(trial.timing_response > 0)
|
||||
{
|
||||
setTimeout(function(){
|
||||
if(!sikr_trial_complete){
|
||||
cont_function();
|
||||
}
|
||||
}, trial.timing_response);
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
var trial_data = {"trial_type": "singleimage_keyresponse", "rt": rt, "a_path": trial.a_path, "key_press": key_press}
|
||||
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
|
||||
$(document).unbind('keyup',resp_func);
|
||||
$this.html('');
|
||||
sikr_trial_complete = true;
|
||||
display_element.html('');
|
||||
setTimeout(function(){block.next();}, trial.timing_post_trial);
|
||||
}
|
||||
}
|
||||
$(document).keyup(resp_func);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user