Randomize Choices issue-not presenting in data #3227
-
Hi everyone! I am trying to randomize the choices in my jsPysch button response trial. However, in the data file the selectedChoiceData column keeps coming up as "null." (The response file is recording 0s and 1s correctly, they're just meaningless without more info). When I get rid of the function that allows for the data to be null (aka forcing it to give one of the choices as an answer) the code breaks. So i know its something about retrieving the choice. But I'm not sure what. (Also more info- I play to make both stimulus and the possible choices variables with multiple trials. I'm just trouble shooting with one trial before I move forward). Any help GREATLY appreciated since I've maxed out co-pilots capabilities (lol). var choices_trial1 = [
{ choice: 'The bee and the ladybug are vakoeing' },
{ choice: 'The bee the ladybug vakoes' }
];
var randomizedChoices = jsPsych.randomization.shuffle(choices_trial1.map(choice => choice.choice));
var originalvideo_test_trial_1 = {
type: jsPsychVideoButtonResponse,
stimulus: ['video/testingphase/bball_belly_rubbing_bee_intrans_ladybug_copy.mp4'],
choices: randomizedChoices,
timeline_variables: choices_trial1,
response_allowed_while_playing: false,
trial_ends_after_video: false,
data: function() {
var lastResponse = jsPsych.data.get().last(1).values()[0];
if (lastResponse && lastResponse.button_pressed) {
var selectedChoice = lastResponse.button_pressed;
var selectedChoiceData = choices_trial1.find(choice => choice.choice === selectedChoice)?.data;
return {
task: 'original_test_trials',
selectedChoiceData: selectedChoiceData ? selectedChoiceData : null
};
} else {
return {
task: 'original_test_trials',
selectedChoiceData: null
};
}
}
};
timeline.push(originalvideo_test_trial_1); i've also tried it this way (which did not work either, clearly) var choices_trial1 = [ var randomizedChoices = jsPsych.randomization.shuffle(choices_trial1.map(choice => choice.choice)); var originalvideo_test_trial_1 = { |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
i tried making it an array too with no luck in the data file: var choices_trial1 = [ var randomizedChoices = jsPsych.randomization.shuffle(choices_trial1); var originalvideo_test_trial_1 = { |
Beta Was this translation helpful? Give feedback.
-
The on_finish: function (data) {
data.task = 'original_test_trials';
if (data.response !== null) {
data.selectedChoiceData = randomizedChoices[data.response];
} else {
data.selectedChoiceData = null;
}
} |
Beta Was this translation helpful? Give feedback.
The
data
property is added at the start of a trial. If you want to add data based on the participant's response in the present trial, you can do it inon_finish
: