working with subsets of timeline variables #1606
Replies: 1 comment
-
UPDATE: Funny how posting a question to the board 7/10 times ends up answering my own question! I remembered that I can use Here is my implementation:
Hoping someone can benefit from this workaround! |
Beta Was this translation helpful? Give feedback.
-
Hi all,
We are working on a new experiment where the participants initially rate some images. If the participant selects neutral ratings (4,5,6) I manipulate the timeline variable array
expStimSubset
to move neutral images to the end of the array and remove any non-neutral ratings (1,2,3,7,8,9) from the array:let likingRating = {
type: "html-keyboard-response",
data: jsPsych.timelineVariable("data"),
stimulus: function(){
var html="<img src='"+jsPsych.timelineVariable('stimulus', true)+"'>";
return html +
"<p> <i> Rate this image from 1 to 9, with 1 indicating that you strongly like the image, 9 indicating that you strongly dislike the image, and 5 indicating that you are neutral towards the image. </i> </p>"
},
on_finish: function(data){
console.log(data.key_press);
console.log(jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press));
rating_liking=parseInt(jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press));
data.rating_liking=String(jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press));
if (data.rating_liking === '4' || data.rating_liking === '5' || data.rating_liking === '6') {
expStimSubset.push(expStimSubset.shift())
} else {
expStimSubset.shift();
}
}
};
jsPsych kindly complains since I have changed shortened the timeline variable when I try to access tuples in
expStimSubset
array that have been removed:jspsych.js:554 Uncaught TypeError: Cannot read property 'data' of undefined at TimelineNode.getTimelineVariableValue (jspsych.js:554) at TimelineNode.findTimelineVariable (jspsych.js:560) at TimelineNode.findTimelineVariable (jspsych.js:563) at TimelineNode.timelineVariable (jspsych.js:575) at TimelineNode.timelineVariable (jspsych.js:581) at TimelineNode.timelineVariable (jspsych.js:581) at jspsych.js:306 at evaluateTimelineVariables (jspsych.js:868) at doTrial (jspsych.js:831) at nextTrial (jspsych.js:822)
It seems this is likely a limitation of the timelineVariable (which is initialized at the start of the experiment). Is there a workaround to this problem that anyone has found (or a different implementation)?
Best,
Josh
Beta Was this translation helpful? Give feedback.
All reactions