mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-11 16:18:11 +00:00
conditional_function only runs with first set of variables #585
This commit is contained in:
parent
e0ee7f02e2
commit
8dd61e6bed
@ -489,8 +489,8 @@ window.jsPsych = (function() {
|
||||
// check for on_timeline_start and conditonal function on nodes with timelines
|
||||
if (typeof timeline_parameters != 'undefined') {
|
||||
// only run the conditional function if this is the first repetition of the timeline when
|
||||
// repetitions > 1
|
||||
if (typeof timeline_parameters.conditional_function !== 'undefined' && progress.current_repetition==0) {
|
||||
// repetitions > 1, and only when on the first variable set
|
||||
if (typeof timeline_parameters.conditional_function !== 'undefined' && progress.current_repetition==0 && progress.current_variable_set == 0) {
|
||||
var conditional_result = timeline_parameters.conditional_function();
|
||||
// if the conditional_function() returns false, then the timeline
|
||||
// doesn't run and is marked as complete.
|
||||
|
@ -301,6 +301,41 @@ describe('conditional function', function(){
|
||||
expect(conditional_count).toBe(1);
|
||||
})
|
||||
|
||||
test('executes only once when timeline variables are used', function(){
|
||||
var conditional_count = 0;
|
||||
|
||||
var trial = {
|
||||
timeline: [{
|
||||
type: 'html-keyboard-response',
|
||||
stimulus: 'foo'
|
||||
}],
|
||||
timeline_variables: [
|
||||
{a:1},
|
||||
{a:2}
|
||||
],
|
||||
conditional_function: function(){
|
||||
conditional_count++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
});
|
||||
|
||||
expect(conditional_count).toBe(1);
|
||||
|
||||
// first trial
|
||||
utils.pressKey(32);
|
||||
|
||||
expect(conditional_count).toBe(1);
|
||||
|
||||
// second trial
|
||||
utils.pressKey(32);
|
||||
|
||||
expect(conditional_count).toBe(1);
|
||||
})
|
||||
|
||||
test('timeline variables from nested timelines are available', function(){
|
||||
var trial = {
|
||||
type: 'html-keyboard-response',
|
||||
|
Loading…
Reference in New Issue
Block a user