jspsych / jsPsych

Create behavioral experiments in a browser using JavaScript
http://www.jspsych.org
MIT License
1.04k stars 672 forks source link

How to set timeline_variables to be a function that filters out stimuli based on participant's previous answers #3423

Open AnafNeves opened 1 day ago

AnafNeves commented 1 day ago

I am working with @DominiqueMakowski to try to set up an experiment in which we need to filter an array of stimuli based on the demographic answers given by the participant at the beginning of the experiment.

However, setting timeline variable to be a function does not seem to work:

timeline.push({
        timeline_variables: function() {return new_stimuli_list}, // new_stimuli_list being created on the on_finish of a previous phase
        timeline: [
            fixactioncross,
            showimage,
        ],
    }
)

We tried as an alternative to put the whole timeline object into a function with the hope that that function would only be called after the demographic phase:

function expe_trials() {
    return {
        timeline_variables: function() {return new_stimuli_list}, // new_stimuli_list being created on the on_finish of a previous phase
        timeline: [
            fixactioncross,
            showimage,
        ],
    }
}
timeline.push(expe_trials())

But that didn't do the trick either, as the function is called immediately on script initialization.

What is the best way to dynamically filter the timeline__variable? Thanks

Shaobin-Jiang commented 1 day ago

Take a look at the documentation. https://www.jspsych.org/latest/overview/timeline/#sampling-methods