Replies: 2 comments 2 replies
-
Hi @fspinar, the first argument to the randomization function has to be an array, but you're indexing the distribution array there, which means that you're passing one of the array elements as the first argument. So try removing the square brackets so that the first argument is just the var result = jsPsych.randomization.sampleWithReplacement(distribution, 1)[0]; Does that work? Also, I noticed that you've included a |
Beta Was this translation helpful? Give feedback.
-
Hi again @becky-gilbert Thanks a lot for your response. For now I just got rid of my loop and defined several parameters manually. But I think the problem is using variable i as the index of the loop. As you said, the loop index becomes inconsistent with the index of global_array while executing the function. Right now defining variable without for loop is OK, so I will go with that. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I am trying to modify a stimulus in a trial by trial basis. The stimulus depends both on answers from subjects, and a probability distribution, which I am defining globally. Then, when I define the stimulus as a function, it seems like I cannot pass the distribution as a parameter to the function. For some reason, despite explicitly adding the variable names as parameters, I cannot access the distribution variable inside the function and I get the following errors :
First argument to jsPsych.randomization.sampleWithReplacement() must be an array
Uncaught TypeError: Cannot read property 'length' of undefined
How can I solve this ? The pseudocode is something like that:
_var distribituon = []; // whatever it is
var trial = {
type: "image-keyboard-response",
stimulus: function (data) {
var result = jsPsych.randomization.sampleWithReplacement(distribution[i], 1)[0];
if(result){
return "image1.png"
}else{
"image2.png"
}
}_
Thank you and best regards.
Beta Was this translation helpful? Give feedback.
All reactions