Ending trial when specific button is selected #3278
-
Hi everyone, I am hoping to end a trial when a specific button is pressed. However, unlike in traditional jsPsychHtmlButtonResponse trials where the button response automatically ends the trial, we need to be able to capture multiple button responses. As a result, I tweaked the jsPsychHtmlButtonResponse plugin by enabling all the buttons after a response is made in order to capture the recording of multiple button presses. As part of the experimental task, we have 2 button options (e.g., 'Like' and 'Skip'). Ultimately, we want to collect multiple button responses, such that some participants may select the 'Like' button and then the 'Skip' button, but critically, whenever a participant selects the 'Skip' button, the trial should automatically end. What would be the best way to go about this? Attaching what the trial would look like below. If there is any other information that would be helpful to provide, please let me know. Thank you so much in advance!
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You could wrap the trial in a child timeline and use the loop function to repeat the trial until "Skip" is clicked, but since a video is involved, that would not be ideal. Alternatively, you could do something like this: var video_trial = {
type: jsPsychHtmlButtonResponse,
stimulus: stimulus: function(){
var html =
'<video autoplay controls muted src="'+jsPsych.timelineVariable('videos')+'"></video>' +
'<img src="images/image1.png"</img>';
return html;
},
choices: ['Like', 'Skip'],
button_html: ['<button class="jspsych-btn">%choice%</button>', '<button class="jspsych-btn">%choice%</button>'],
response_ends_trial: false /*making this false in order to be able to capture multiple button presses*/,
trial_duration: jsPsych.timelineVariable('video_time'),
on_load: function () {
// Remove the default event listeners on the buttons
let btn_group = document.querySelector('#jspsych-html-button-response-btngroup');
btn_group.innerHTML = btn_group.innerHTML;
let response = [];
let start_time = performance.now();
for (let button of document.querySelectorAll('button')) {
button.addEventListener('click', function (e) {
let val = e.target.innerHTML;
response.push(val);
if (val == 'Skip') {
jsPsych.finishTrial({rt: performance.now() - start_time, response});
jsPsych.getDisplayElement().innerHTML = '';
}
});
}
},
}; |
Beta Was this translation helpful? Give feedback.
You could just make
response
andrt
global variables (i.e., by declaring from outside ofon_load
). Then, if the trial ends without "skip" being clicked, just append the data inon_finish
.