depending on number of button presses, different stim #3327
Unanswered
Student-coding1
asked this question in
Q&A
Replies: 1 comment
-
let stim = {
type: jsPsychHtmlKeyboardResponse,
stimulus: 'stim',
choices: ['z'],
};
timeline.push(stim);
let optional_stim = {
timeline: [
{
type: jsPsychHtmlKeyboardResponse,
stimulus: 'stim',
choices: ['z'],
trial_duration: () => 1500 - jsPsych.data.getLastTrialData().values()[0].rt,
},
],
conditional_function: function () {
return jsPsych.data.getLastTrialData().values()[0].rt < 1500;
},
};
timeline.push(optional_stim);
let stim_g = {
type: jsPsychHtmlKeyboardResponse,
stimulus: 'stim longer than 1500ms',
choices: ['z'],
on_finish: function (data) {
jsPsych.data.addProperties({
reaction_time: data.rt,
});
},
};
let stimulus_longer = {
timeline: [stim_g],
conditional_function: function () {
let last_trial_data = jsPsych.data.getLastTrialData().values()[0];
let rt = last_trial_data.rt;
let response = last_trial_data.response;
// rt < 1500 indicates that optional_stim must be run
// response != null indicates that two key presses are made
return rt < 1500 && response != null;
},
};
timeline.push(stimulus_longer);
let stim_1 = {
type: jsPsychHtmlKeyboardResponse,
stimulus: 'stim shorter than 1500ms',
choices: ['z'],
};
let stimulus_shorter = {
timeline: [stim_1],
conditional_function: function () {
let last_trial_data = jsPsych.data.getLastTrialData().values()[0];
let rt = last_trial_data.rt;
let response = last_trial_data.response;
return !(rt < 1500 && response != null);
},
};
timeline.push(stimulus_shorter); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am struggling with my code, I would like that if the participants presses the button A twice within 1500ms, it would show stim_g, if the participant only pressed the button A once within 1500ms it needs to show stim_1. But I seem to do something wrong in the coding.
Does anybody have any advice pleas?
Thanks in advances!
var stim = {
type: 'html-keyboard-response',
stimulus: "stim",
choices:['z'],
}
timeline.push(stim)
var stim_g = {
type: 'html-keyboard-response',
stimulus: "stim longer than 1500ms",
choices:['z'],
on_finish: function(data){
jsPsych.data.addProperties({
reaction_time: data.rt,
})
}
};
var stimulus_longer = {
timeline: [stim_g],
conditional_function: function(){
var last_trial_data = jsPsych.data.getLastTrialData();
var data = jsPsych.data.get().last(1).values()[0];
while (data.rt < 1500) {
if(jsPsych.data.get().last(2).count() == 2){
return false
} else{
return true
}
}
}
};
timeline.push(stimulus_longer)
var stim_1 = {
type: 'html-keyboard-response',
stimulus: "stim shorter than 1500ms",
choices:['z'],
};
var stimulus_shorter = {
timeline: [stim_1],
conditional_function: function(){
var last_trial_data = jsPsych.data.getLastTrialData();
var data = jsPsych.data.get().last(1).values()[0];
while (data.rt > 1500) {
return false
} else{
return true
}
}
};
timeline.push(stimulus_shorter)
Beta Was this translation helpful? Give feedback.
All reactions