-
Hello everyone, I didn't saw this new forum! Here is a question I posted on the jsPsych google group few days ago :) For each trial of my experiment, I have to display two half images that form one big image. I've preloaded all my images in the jsPsych.init and all the images' files (left and right) are listed in the timeline variable. My experiment is pretty long (around 300 trials that include the choice screen and a feedback screen) and for some of the trials the feedback images are asynchronously displaid... This is a problem because the participant must see only one big image and not two half images. Thank you by advance, var respS_exp = {
type: 'html-keyboard-response',
choices: jsPsych.NO_KEYS,
trial_duration: feedback_time,
timeline: [
{stimulus: function(){//mask display
var MasqueL = F2 + SequenceL[SequenceL.length-1].slice(F.length, F.length+3) + '.jpg' ;
var MasqueR = F2 + SequenceR[SequenceR.length-1].slice(F.length, F.length+3) + '.jpg' ;
return "<img src=" + MasqueL + " align='center' width=46% style='z-index:1'></img>"+
"<img src=" + MasqueR + " align='center' width=46% style='z-index:1'></img>"
},
trial_duration: mask_time},
{stimulus: function(){//feedback display
ImageL = SequenceL[SequenceL.length-1];
ImageR = SequenceR[SequenceR.length-1];
if( jsPsych.timelineVariable('rewardL', true)== 1){
hit = 1;
let r = Math.random();
if (r<0.8){
var persoR = ImageR.slice(0,F.length+6);
var sideR = ImageR.slice(F.length+9, ImageR.length);
var emoR = 'A_7';
ImageR = persoR + emoR + sideR;
rewarded = true;
}else{
var persoL = ImageL.slice(0,F.length+6);
var sideL = ImageL.slice(F.length+9, ImageL.length);
var emoL = 'A_7';
ImageL = persoL + emoL + sideL;
rewarded = false;
}
}else{
hit = -1;
let r = Math.random();
if (r<0.8){
var persoL = ImageL.slice(0,F.length+6);
var sideL = ImageL.slice(F.length+9, ImageL.length);
var emoL = 'A_7';
ImageL = persoL + emoL + sideL;
rewarded = false;
}else{
var persoR = ImageR.slice(0,F.length+6);
var sideR = ImageR.slice(F.length+9, ImageR.length);
var emoR = 'A_7';
ImageR = persoR + emoR + sideR;
rewarded = true;
}
}
return "<img src=" + ImageL + " align='center' width=46% style='z-index:1'></img>"+
"<img src='img/CROSS3.png' height='20px' width='20px' style='position:absolute; top: 12.7%; left: 49.2%; z-index:2'></img>"+
"<img src=" + ImageR + " align='center' width=46% style='z-index:1'></img>"+
"<img src='img/check.png' height='80px' width='80px' style='position:absolute; bottom: 45%; left: 13%; z-index:2'></img>"
},
on_finish: function(data){
[...]
}
}
]
}; |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
@jodeleeuw, I can't seem to be able to edit discussions? Anyways, here's the code formatted a bit better. var respS_exp = {
type: "html-keyboard-response",
choices: jsPsych.NO_KEYS,
trial_duration: feedback_time,
timeline: [
{
stimulus: function() {
//mask display
var MasqueL =
F2 +
SequenceL[SequenceL.length - 1].slice(F.length, F.length + 3) +
".jpg";
var MasqueR =
F2 +
SequenceR[SequenceR.length - 1].slice(F.length, F.length + 3) +
".jpg";
return (
"<img src=" +
MasqueL +
" align='center' width=46% style='z-index:1'></img>" +
"<img src=" +
MasqueR +
" align='center' width=46% style='z-index:1'></img>"
);
},
trial_duration: mask_time
},
{
stimulus: function() {
//feedback display
ImageL = SequenceL[SequenceL.length - 1];
ImageR = SequenceR[SequenceR.length - 1];
if (jsPsych.timelineVariable("rewardL", true) == 1) {
hit = 1;
let r = Math.random();
if (r < 0.8) {
var persoR = ImageR.slice(0, F.length + 6);
var sideR = ImageR.slice(F.length + 9, ImageR.length);
var emoR = "A_7";
ImageR = persoR + emoR + sideR;
rewarded = true;
} else {
var persoL = ImageL.slice(0, F.length + 6);
var sideL = ImageL.slice(F.length + 9, ImageL.length);
var emoL = "A_7";
ImageL = persoL + emoL + sideL;
rewarded = false;
}
} else {
hit = -1;
let r = Math.random();
if (r < 0.8) {
var persoL = ImageL.slice(0, F.length + 6);
var sideL = ImageL.slice(F.length + 9, ImageL.length);
var emoL = "A_7";
ImageL = persoL + emoL + sideL;
rewarded = false;
} else {
var persoR = ImageR.slice(0, F.length + 6);
var sideR = ImageR.slice(F.length + 9, ImageR.length);
var emoR = "A_7";
ImageR = persoR + emoR + sideR;
rewarded = true;
}
}
return (
"<img src=" +
ImageL +
" align='center' width=46% style='z-index:1'></img>" +
"<img src='img/CROSS3.png' height='20px' width='20px' style='position:absolute; top: 12.7%; left: 49.2%; z-index:2'></img>" +
"<img src=" +
ImageR +
" align='center' width=46% style='z-index:1'></img>" +
"<img src='img/check.png' height='80px' width='80px' style='position:absolute; bottom: 45%; left: 13%; z-index:2'></img>"
);
},
on_finish: function(data) {
// [...]
}
}
]
}; |
Beta Was this translation helpful? Give feedback.
-
I don't think there's necessarily a way to fix this without significant code changes. The way jsPsych preloads images means that we cannot access the image cache directly and have to rely on the browser determining that the image is already cached, which causes the lag sometimes. Atleast this is my hypothesis. Line 2283 in 8398008 To fix this, you would need to maintain your own image cache and preload mechanism, and refer to it using the on_load callback function. I've linked to the part of jsPsych that might contain hints, but let me know if you'd like more concrete guidance! |
Beta Was this translation helpful? Give feedback.
-
Hi, |
Beta Was this translation helpful? Give feedback.
Hi,
I've finally fixed my problem. One of my colleagues noticed that the asynchronous display was due to the fact that one of the two half images was already displayed before the feedback. That is why it was more rapidly displayed. The solution was to display the other half image earlier in the experience hiding it behind the image that we want to show at this moment of the experiment. In this way, we have no more asynchronous display (even with firefox).
Thanks for all your help,
Best,
IM