Why does the while loop repeat the current trial once? #835
-
Hello, I am currently trying to implement a while logic in my timeline: the trial repeats unless one clicks on the correct button. and my code is behaving in a quite bizarre way. If I hit the “happy” button first, it will show me the current trial over and over again, which is the desired feature. However, when I hit the “sad” button, it does not move on to the next trial but will present the current trial another time. For this repeated presentation, it will move on to the next trial when I hit either “happy” or “sad”. Here's what I have for the two key components. Both of them are pushed to the timeline. While_loop was pushed after the picture_trial var picture_trial = {
type: 'image-button-response',
stimulus: 'images/chicken_blueberries.jpg',
choices: ['Happy', 'Sad'],
prompt: "<p>Which of these patterns do you like better?</p>",
on_finish: function(data) {
if(data.button_pressed == 0){
data.correct = true;
} else {
data.correct = false;
}
}};
var while_loop = {
timeline: [picture_trial],
loop_function: function(data){
if(data.values()[0].correct){ // this line must be buggy
return false;
} else {
return true;
} Any suggestion would be deeply appreciated!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The picture trial should not be pushed on to the timeline, just the while_loop, otherwise you'll be shown a normal trial that shows the picture and then the loop sequence instead of only the loop sequence itself. |
Beta Was this translation helpful? Give feedback.
The picture trial should not be pushed on to the timeline, just the while_loop, otherwise you'll be shown a normal trial that shows the picture and then the loop sequence instead of only the loop sequence itself.