我在时间线上有 n 次决策试验。正确答案被记录为数据属性。如果参与者提供了固定数量的正确答案,我想跳过时间线的其余部分。这需要一个条件,但我的不起作用。
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
var data = jsPsych.data.get()
var correct_count = data.filter({correct: true}).count();
return correct_count < 2
}
}
下面的可重现代码(需要 jspsych-6)。
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych-6/jspsych.js"></script>
<script src="jspsych-6/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6/plugins/jspsych-html-button-response.js"></script>
<link href="jspsych-6/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/* create timeline */
var timeline = [];
/* test trials */
var test_stimuli = [
{ word: "table", data: { false_word: '0' } },
{ word: "tfble", data: { false_word: '1' } },
{ word: "tablw", data: { false_word: '1' } }
];
var trial = {
type: ["html-button-response"],
stimulus: jsPsych.timelineVariable('word'),
choices: ["real", "fake"],
margin_vertical: "0px",
margin_horizontal: "8px",
response_ends_trial: true,
post_trial_gap: [500],
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.false_word == data.button_pressed
}
};
var test_procedure = {
timeline: [trial],
timeline_variables: test_stimuli
}
//timeline.push(test_procedure);
var if_node = {
timeline: [test_procedure],
conditional_function: function(){
var data = jsPsych.data.get()
var correct_count = data.filter({correct: true}).count();
return correct_count < 2
}
}
timeline.push(if_node);
/* start the experiment */
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>