jsPsych.randomization.sampleWithoutReplacement - saving output? #1463
-
I have the following code: var feedback= [];
var feedback_one = {
type: "image-keyboard-response",
trial_duration: 2000,
stimulus:function(){
var feedback1;
var last_trial_correct=jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct){
return feedback1 = jsPsych.randomization.sampleWithoutReplacement(button_pressed, 1); //Return 1 stimuli sampled from the randomized button pressed array without replacement
} else {
return feedback1 = jsPsych.randomization.sampleWithoutReplacement(button_notpressed, 1) //Return 1 stimuli sampled from the randomized button not pressed array without replacement
}
data.correct=feedback1;
feedback.push(feedback1); However, in my code I receive an error that states "data.correct=feedback1" is unreachable. I want to return an array of the randomly presented stimuli. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @chester108, I'm not sure based on the code you provided, but I think the last two lines are supposed to be inside of the stimulus function - is that right? If so, then I don't think those lines will be called because you're returning from the function before that point in the code. var feedback= [];
var feedback_one = {
type: "image-keyboard-response",
trial_duration: 2000,
on_start: function(trial){
var feedback1;
var last_trial_correct=jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct){
feedback1 = jsPsych.randomization.sampleWithoutReplacement(button_pressed, 1); //Return 1 stimuli sampled from the randomized button pressed array without replacement
} else {
feedback1 = jsPsych.randomization.sampleWithoutReplacement(button_notpressed, 1) //Return 1 stimuli sampled from the randomized button not pressed array without replacement
}
trial.data.correct=feedback1; // store feedback1 as 'correct' in the trial data
trial.stimulus = feedback1; // make feedback1 the stimulus for this trial
feedback.push(feedback1); // add feedback1 to the feedback array
},
// other trial parameters
}; I hope this helps! Let us know if you need further guidance. |
Beta Was this translation helpful? Give feedback.
Hi @chester108, I'm not sure based on the code you provided, but I think the last two lines are supposed to be inside of the stimulus function - is that right? If so, then I don't think those lines will be called because you're returning from the function before that point in the code.
Also, you don't have access to the
data
object from inside thestimulus
function, so you can't update the data in astimulus
function in the way that you can from inside a trial'son_finish
function.I'm not sure if this would work, but you could try moving the code from your
stimulus
function into the trial'son_start
parameter. This function will run before the trial starts and has access to the trial par…