Replies: 4 comments
-
I figure out a way to execute the function that I wanted. However, now "block" is not executed, it is just skipped. This is my code so far: var trials = [];
var timeline = [];
var images = [
"img/1.png", "img/2.png", "img/3.png", "img/4.png",
"img/5.png", "img/6.png"
];
var instructions = {
type: "html-keyboard-response",
stimulus: "<p>Waiting for the inputs</p> ",
choices: ['x'],
post_trial_gap: 1000
};
timeline.push(instructions);
var evaluation = {
type: 'call-function',
func: function() {
for (var i = 0; i < all_states.length;) {
var tmppath = all_states[i];
trials.push({
stimulus: images[tmppath]
});
i++
}
}
};
timeline.push(evaluation);
var block = {
type: 'image-keyboard-response',
choices: jsPsych.NO_KEYS,
prompt: '<p>Display of images.</p>',
trial_duration: function(){
return jsPsych.randomization.sampleWithoutReplacement([1000], 1)[0];
},
on_finish: function(data) {
if (data.key_press == 40) {
jsPsych.endCurrentTimeline();
}
},
timeline: trials
}
timeline.push(block);
var after_block = {
type: 'html-keyboard-response',
stimulus: '<p>The trial is finished</p>',
is_html: true
}
timeline.push(after_block);
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData();
}
}); Does anyone have any idea why "block" is no being executed? Thanks for your attention. |
Beta Was this translation helpful? Give feedback.
-
I think the problem is that Your function in the call-function plugin isn't going to achieve what you're aiming for. The timeline can't be modified on the fly in this particular way. There's one function that allows for timeline modification, but this form of timeline construction is something that we will add more support for in a future release. The solution here is probably to add a |
Beta Was this translation helpful? Give feedback.
-
Thank you jodeleeuw. This is the new code:
Do you know how to fix it, to display an image for each cycle of the loop? Thanks again for your attention! |
Beta Was this translation helpful? Give feedback.
-
In the end, this was my solution:
|
Beta Was this translation helpful? Give feedback.
-
I want to use a function between two blocks. This function will set the order of the stimulus that I want to present. The variables that are in the function are called from another script.
This is part of my code:
Any suggestions?
Thanks in advance of your attention and help.
Beta Was this translation helpful? Give feedback.
All reactions