Maintaining a shuffled order of choices across two trials in a nested timeline #1398
-
Hello! (I apologize if this has been asked before.) I am creating an experiment where participants have to choose between two pictures after listening to an audio stimulus. Specifically, I will play two versions of the audio stimulus such that I have to create two separate trials. The picture should be the same across the two trials. My question is about randomizing the order of the buttons and maintaining that order across the two trials. I want to randomize the order of buttons across the entire experiment, but the order of the buttons should be kept the same between the two trials (i.e., step1 and step2). Is there a way to achieve this? Thank you so much in advance! I have created a nested timeline, and here is my code: var test_stimuli = [
{test_audio1:"A1.wav", test_audio2:"A2.wav", test_choices:["picture1","picture2"]},
{test_audio1:"B1.wav", test_audio2:"B2.wav", test_choices:["picture3","picture4"]},
{test_audio1:"C1.wav", test_audio2:"C2.wav", test_choices:["picture5","picture6"]},
]
var test_trial = {
type:'audio-button-response',
choices: jsPsych.timelineVariable('test_choices'),
button_html: '<button class="jspsych-btn"> <img src="img/%choice%.jpg"></button>',
timeline: [
{//Step1: Audio1 only and no response allowed
stimulus: jsPsych.timelineVariable('test_audio1'),
response_allowed_while_playing: false,
trial_ends_after_audio: true,
on_start: function(trial) {
var shuffled_label_choices = jsPsych.randomization.shuffle(trial.choices)
trial.choices = shuffled_label_choices
trial.data = {button_choices:shuffled_label_choices}
}
},
{//Step2: Audio2 and response allowed
stimulus: jsPsych.timelineVariable('test_audio2'),
response_allowed_while_playing: true,
trial_duration: 5000,
post_trial_gap: 300,
on_finish: function(data) {
var test_part = "test"
button_number = data.button_pressed
data.button_selected = data.button_choices[button_number]}
}
},
],
timeline_variables: test_stimuli,
randomize_order: true
};
timeline.push(test_trial); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @rachelkytsui, I'm having a hard time coming up with a super-elegant way to do this, but I think that taking advantage of the on_start: function(trial){
trial.choices = jsPsych.data.get().last(1).values()[0].button_choices;
} This works because you've saved |
Beta Was this translation helpful? Give feedback.
-
@jodeleeuw Amazing, it works now! Thank you so so much! |
Beta Was this translation helpful? Give feedback.
Hi @rachelkytsui,
I'm having a hard time coming up with a super-elegant way to do this, but I think that taking advantage of the
on_start
parameter like you did for Step1 makes sense. In Step2, you could do this:This works because you've saved
shuffled_label_choices
to the data object for the Step1 trial.