Modify a timeline to execute if a condition is met
display_if(timeline, conditional_function)
timeline | A timeline object |
---|---|
conditional_function | A javascript function that returns true if the timeline should execute and false otherwise |
The modified timeline object
The display_if()
function is used to modify an existing
timeline
object, and provides the ability for conditional branching
within an experiment. To use it, the user must supply the
conditional_function
, a javascript function that executes at
runtime and should evaluate to true or false. If the
conditional function returns true, then the timeline object
will execute; if the conditional function returns false then jsPsych
will not run this timeline.
At present jaysire provides only limited tools for writing the
conditional function. The fn_data_condition()
function allows
a simple approach that allows the conditional function to query the
jsPsych data store, but only in a limited way. Future versions will
(hopefully) provide a richer tool set for this. However, for
users who are comfortable with writing javascript functions directly
the insert_javascript()
function may be useful.