Save content of button response not its index #1687
-
Hi, var use_info = {
type: 'html-button-response',
stimulus: '<span style="font-size:36px; ">What would you like to do?</span>',
choices: function(data) {
if (show==1){
list_options= gorilla.shuffle (['<span style="font-size:30px; ">gather 5 stocks</span>','<span style="font-size:30px; ">nothing</span>', '<span style="font-size:30px; ">give away 5 stocks</span>'])
return list_options
} else if (show==0){
list_options= gorilla.shuffle(['<span style="font-size:30px; ">nothing</span>', '<span style="font-size:30px; ">nothing</span>' , '<span style="font-size:30px; ">nothing</span>'])
return list_options
}
},
on_finish: function(data) {
decision = jsPsych.data.getLastTrialData().values()[0].button_pressed
}
};
timeline.push(use_info); Thank you very much for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi Valentina, Great question. If you're using jsPsych v6.3.0, there's an easy way to do this. You can save the randomized button choice labels to the trial data using the new If you're using a version of jsPsych <6.3.0, then the // make list_options a global variable
var list_options;
var use_info = {
type: 'html-button-response',
stimulus: '<span style="font-size:36px; ">What would you like to do?</span>',
choices: function(data) {
if (show==1){
list_options= gorilla.shuffle (['<span style="font-size:30px; ">gather 5 stocks</span>','<span style="font-size:30px; ">nothing</span>', '<span style="font-size:30px; ">give away 5 stocks</span>'])
return list_options
} else if (show==0){
list_options= gorilla.shuffle(['<span style="font-size:30px; ">nothing</span>', '<span style="font-size:30px; ">nothing</span>' , '<span style="font-size:30px; ">nothing</span>'])
return list_options
}
},
on_finish: function(data) {
// find the label of the button that was pressed by indexing the current list_options array with the button_pressed index
data.decision = list_options[data.button_pressed];
}
};
timeline.push(use_info); Note that, in the I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Hi Becky, Thanks again! |
Beta Was this translation helpful? Give feedback.
Hi Valentina,
Great question. If you're using jsPsych v6.3.0, there's an easy way to do this. You can save the randomized button choice labels to the trial data using the new
save_trial_parameters
parameter that's available in all plugins. And in theon_finish
function, you could also add a property to the trial data that contains the label of the button that was pressed. In the jsPsych examples folder, there's an example file called "save_trial_parameters.HTML" - the 3rd example trial in that file shows exactly how to do this.If you're using a version of jsPsych <6.3.0, then the
save_trial_parameters
option doesn't exist. So another way to do this is to make thelist_options
array into …