Modify a timeline to set possible values for variables

set_variables(timeline, ...)

## Arguments

timeline The timeline object A set of name/value pairs defining the timeline variables

## Value

The modified timeline object

## Details

When creating an experiment, a common pattern is to create a series of trials that are identical in every respect except for one thing that varies across the trial (e.g., a collection of trial_html_button_response() trials that are the same except for the text that is displayed). A natural way to handle this in the jsPsych framework is to create the trial in the usual fashion, except that instead of specifying the value that needs to be included in the trial (e.g., the text itself) the code includes a reference to a timeline variable. Inserting the reference to the variable is the job of the insert_variable() function; attaching that variable to the timeline and specifying its possible values is the job of set_variables. This is most easily explained by using an example, as shown below.

build_timeline, insert_variable

## Examples

# create a template from which a series of trials can be built
template <- trial_html_button_response(stimulus = insert_variable("animal"))

# create a timeline with three trials, all using the same template
# but with a different value for the "animal" variable
timeline <- build_timeline(template) %>%
set_variables(animal = c("cat", "dog", "pig"))