In one section of my study, reproducible example attached, feedback should be, “correct” when nothing is pressed, and the stimulus<< has been presented. However if a key is pressed in this condition, the feedback is, “do not respond”[
And when M is pressed to a >> we should see, “correct” and FZ is pressed instead, we should say, “incorrect” this all works locally, as can be seen in the attached. Yet when I run this very same study online, the feedback is it not as intended. I am sure that I am thinking the correct file because of the changes that I made locally are reflected online, it is just the feedback that works locally but not online.
https://run.pavlovia.org/TSKang/halfsimon1415
Many thanks in advance
halfsimontest.psyexp (13.3 KB) HalfSimonPract.csv (135 Bytes)
Hey!
A good first step in finding out what’s going wrong is adding some debugging code. See this tutorial to get started: Thomas Pronk / tutorial_js_console_log · GitLab
Best, Thomas
Thank you! Looks like it’s throwing some kind of errors, but I’m afraid I don’t understand what any of this means!
I hope this screenshot will enable you to read some of this?
The 404 error is nothing to worry about. For the rest there are no errors in there, so you’ve got a bug that doesn’t cause any problems in the code, but unexpected behavior. Make copious use of console.log
inside of your code components to log all kinds of stuff and see what happens.
Okay, but I don’t think there is anything unusual with my Psychopy code, it works as expected on my machine. It is only once uploaded to Pavlovia that unusual behaviour occurs. z what I meant to say is all the feedback functions correctly on my laptop, but when I run exactly the same thing online, it’s not appearing as intended. It’s logical to believe that there is something about the online implementation that’s causing the problem, not my local code, no?
Okay, so the next thing I think might be worth investigating is the automatic JavaScript translation of my Python code. I will post a screenshot of that below. Maybe there is some error in the translation, and obviously I won’t know any better, because I don’t know JavaScript!
I am certain that the pricing code works, because it works perfectly for me, and for my advisor. So it can’t be anything unusual about my computer, either.
Here is the code component which shows what I have entered, that works locally, and the conversion provided by the software.
Yeah, there are indeed some issues with the autotranslation; thnx for the update! I’ll go make some notes of these and provide you with a solution later on. However, to test that solution I’d still recommend a lot of debug logging 
Could you copy paste both the Python and JS into a comment? Please surround them by triple backticks (topleft on your keyboard) so that the formatting is maintained
Functional python code
msg = " "
if PRespp.corr: msg = "correct"
if N == 0 and PRespp.corr == 0: msg = "do not respond"
if N == 1 and PRespp.corr == 0 and PRespp.rt == []: msg = "too slow"
elif N == 1 and PRespp.corr == 0: msg = "incorrect"
Dysfunctional auto generated JavaScript code
msg = " ";
if (PRespp.corr) {
msg = "correct";
}
if (((N === 0) && (PRespp.corr === 0))) {
msg = "do not respond";
}
if ((((N === 1) && (PRespp.corr === 0)) && (PRespp.rt === []))) {
msg = "too slow";
} else {
if (((N === 1) && (PRespp.corr === 0))) {
msg = "incorrect";
}
}
Thank you in advance for your help!
You’re welcome! This might fix it, but I’m not 100% sure. I added a lot of debug code so that if it goes wrong, we can pinpoint why
console.log('values used in if statement')
console.log(PRespp.corr)
console.log(N)
console.log(PRespp.rt)
msg = " ";
if (PRespp.corr) {
msg = "correct";
console.log('correct');
}
if (((N === 0) && (PRespp.corr === 0))) {
msg = "do not respond";
console.log('do not respond');
}
if ((((N === 1) && (PRespp.corr === 0)) && (PRespp.rt.length === 0))) {
msg = "too slow";
console.log('too slow');
} else if (((N === 1) && (PRespp.corr === 0))) {
msg = "incorrect";
console.log('incorrect');
}
console.log('msg after code block executed');
console.log(msg);
Okay, well following the debugging steps in the post you shared earlier, I get this error message,
core-2021.1.2.js:1924 TypeError: Cannot read property 'length' of undefined
at Scheduler._currentTask (halfsimontest.js:364)
at Scheduler._runNextTasks (util-2021.1.2.js:1560)
at Scheduler._runNextTasks (util-2021.1.2.js:1564)
at Scheduler._runNextTasks (util-2021.1.2.js:1564)
at update (util-2021.1.2.js:1514)
window.onerror @ core-2021.1.2.js:1924
error (async)
_captureErrors @ core-2021.1.2.js:1922
PsychoJS @ core-2021.1.2.js:1604
(anonymous) @ halfsimontest.js:17
log4javascript.min.js:1 FATAL unknown | {}
I guess it is related to the first line of that third if statement?
It’s this part
PRespp.rt.length === 0
But in this case there might also be a bug in your Python? If a property is undefined in JS, it’s None in Python. I assumed that what you’re checking in this Python-expression is whether an array of RTs is empty.
PRespp.rt == []
However, if I run these tests I get some strange results:
>>> x = []
>>> x == []
True
>>> x = None
>>> x == []
False
Yes, that is exactly what we want to check, . But when I run this code locally, it does what I expect? I’m sorry, but that’s why I was under the impression that there is nothing wrong with my Python, because it looks perfectly on my computer. Likewise, both my advisor and I have repeatedly tried to break it, and describe the expected behaviour, but it holds up really well!
*disrupt the expected behaviour
Fine with me :). Then this should make that part behave the same.
console.log('values used in if statement')
console.log(PRespp.corr)
console.log(N)
console.log(PRespp.rt)
msg = " ";
if (PRespp.corr) {
msg = "correct";
console.log('correct');
}
if (((N === 0) && (PRespp.corr === 0))) {
msg = "do not respond";
console.log('do not respond');
}
if ((((N === 1) && (PRespp.corr === 0)) && (PRespp.rt !== undefined && PRespp.rt.length === 0))) {
msg = "too slow";
console.log('too slow');
} else if (((N === 1) && (PRespp.corr === 0))) {
msg = "incorrect";
console.log('incorrect');
}
console.log('msg after code block executed');
console.log(msg);
``
Unfortunately not, I think we must be getting really close though! The issue is that when I make no response to >> I would expect your message, “too slow” this is correctly defined in the stimulus control file right at the top of the thread. But I always receive the message, “incorrect” even though if they do nothing in this context the appropriate feedback is, “slow” and they should only see the message, “incorrect” if they press any inappropriate key, instead of doing nothing. Does that make sense
I added a whole bunch of debug statements via console.log, so that we can see what the values are used in the if-stament. What does this part report in the browser console?
console.log('values used in if statement')
console.log(PRespp.corr)
console.log(N)
console.log(PRespp.rt)
values used in if statement
halfsimontest.js:352 0
halfsimontest.js:353 1
halfsimontest.js:354 undefined
halfsimontest.js:369 incorrect
halfsimontest.js:371 msg after code block executed
halfsimontest.js:372 incorrect
halfsimontest.js:373 msg after code block executed
halfsimontest.js:374 incorrect
Strange, but that’s enough info I think. That one part of the if-statement should be this then
Is the PRespp.rt property one that automatically gets generated by a PsychoPy component?