Replies: 1 comment
-
Hi @kumi5221, I'm really sorry for the delay getting back to you. This is an interesting problem. I'm not totally sure I understand what you're trying to do, but I think part of what you want to do is exit the timeline_variables trials once a certain threshold is reached (i.e. a certain number of 'y' responses). The problem with using a loop_function along with timeline_variables for this is that the loop_function is only called after all of the timeline_variables are repeated over, not after each trial. So if you want to be able to stop a trial procedure that uses timeline variables, then I would use your approach of ending the current timeline with var words_list = [{stimulus: 'foo'},{stimulus: 'bar'},{stimulus: 'buzz'},{stimulus: 'fizz'}];
var key_press = null;
var end = false;
var count = 0;
var interpreted_num = 1;
var fixation = {
type: 'html-keyboard-response',
stimulus: '+',
choices: jsPsych.NO_KEYS,
trial_duration: 250,
}
var blank = {
type: 'html-keyboard-response',
stimulus: "",
choices: jsPsych.NO_KEYS,
trial_duration: 250
}
var interpretability = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus'),
choices: ['y', 'n'],
//data: jsPsych.timelineVariable('data'),
on_finish: function (data) {
key_press = data.key_press
}
}
var interpretation = {
type: 'survey-text',
questions: [{ prompt: "Enter your interpretation below.", columns: 50, required: true }]
}
var interpretable = {
timeline: [interpretation],
conditional_function: function () {
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(key_press) == 'y') {
count++;
return true;
} else {
return false;
}
},
on_finish: function () {
if (count >= interpreted_num) {
end = true;
}
}
}
var check = {
type: 'call-function',
func: function() {
if (end) {
// this method now works because it's being called on the main task timeline,
// rather than from inside of a conditional node
jsPsych.endCurrentTimeline();
}
}
}
var task = {
timeline: [fixation, blank, interpretability, interpretable, check],
timeline_variables: words_list,
repetitions: 1,
// on_start: function() {
// //data.wordset = set
// //when set=17 and increments it
// // if (++set >= num_set) { set = 0 }
// // words_list = create_nonwords(set) //update the stimuli
// },
};
timeline.push(task) Does that help? |
Beta Was this translation helpful? Give feedback.
-
I'm making an experiment where participants answer yes or no to the same question with different stimuli, and they can exit from the experiment when the number of yes responses reach a certain number.
My timeline structure looks like this:
`
var set = Math.floor(Math.random()*(num_set))
var words_list = create_nonwords(set)
...
var fixation = {
type: 'html-keyboard-response',
stimulus: '
choices: jsPsych.NO_KEYS,
trial_duration: 250,
}
var blank = {
type: 'html-keyboard-response',
stimulus: "",
choices: jsPsych.NO_KEYS,
trial_duration: 250
}
var interpretability = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus'),
choices: ['y', 'n'],
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
key_press = data.key_press
}
}
var interpretation = {
type: 'survey-text',
questions: [{ prompt: "Enter your interpretation below.", columns: 50, required:true}]
}
var count = 0;
var interpreted_num = 10
var interpretable = {
timeline: [interpretation],
conditional_function: function(){
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(key_press) == 'y'){
count++;
return true;
} else {
return false;
}
},
on_finish: function(){
if (count>=interpreted_num){
var parent = this.parent_node; //not working
parent.jsPsych.endCurrentTimeline();
jsPsych.finish_trial();
}
}
var task = {
timeline: [fixation, blank, interpretability, interpretable],
timeline_variables: words_list,
repetitions: 1,
on_start: function(data){
data.wordset = set
//when set=17 and increments it
if (++set >= num_set){set = 0}
words_list = create_nonwords(set) //update the stimuli
},
/*
loop_function: function(data){
if(count < interpreted_num){
return true;
} else {
return false;
}
}
*/
};
timeline.push(task)
`
I'm thinking of two ways to achieve what I want.
end the timeline named 'task' inside the nested sub-timeline 'interpretable' when the 'count' reaches 'interpreted_num'.
->problem: there is no API to end the parent timeline or a particular timeline from a child node. I want to end only the task timeline, not the whole experiment.
In the looped function in the task timeline, create another stimulus set, which is a subset of the original set, so that after each subset, evaluate the count and end the loop in the current level of node 'task'. I wrote the function that creates a new subset of stimulus, different from what is previously shown, and update the stimulus in the on_start of the 'task' timeline.
-> problem: the timeline_variable seems to be called only once when the task is added to the timeline, so it keeps using the original list even after the list is updated.
Could anybody help me figure out how to do either of theses or new solutions? I really appreciate your help.
Beta Was this translation helpful? Give feedback.
All reactions