Hi all,
URL of experiment: https://run.pavlovia.org/Alipour/selfpacedreadingtask https://gitlab.pavlovia.org/Alipour/selfpacedreadingtask
I have put together a self-paced reading task and finally that everything is working perfectly from the Builder view in PsychoPy, I pushed it to Pavlovia to run it online and you guessed it right, I receive JS errors here. Now I fixed some of it by myself but I’m totally new to this, so any help is much appreciated.
Description of the problem: * TypeError: Cannot read property ‘getKeys’ of undefined
ps: the experiment status is private. I couldn’t change it to public but here are the codes: Begin Experiment
if wordNum>oldWordNum:
phrase+=words[wordNum]+' '
text.text=words[wordNum]
oldWordNum=wordNum
theseKeys = psychoJS.EventManager.getKeys()
if 'space' in keys:
wordNum+=1
thisExp.addData("Word"+str(wordNum),myClock.getTime())
myClock.reset()
if wordNum==nWords:
continueRoutine=False
After adding the psychoJS prefix, I rewatched part of a tutorial in which the guy was working with JS. That’s why I entered theseKeys that should be obviously omitted.
You are writing code on the Python side that won’t work locally in order to get the correct JS code. I do do this sometimes, but it’s not my recommended method (which is code_JS to make as much correct Python code as possible translate into correct JS code – see my crib sheet).
Dear @wakecarter,
I did read your crib sheet, but I’ll look into it once more. So I receive this error and I know exactly why.
ReferenceError: keys is not defined
Should i just start from scratch and rewrite everything in JS? And could you tell me how to define keys? sorry for asking too many questions. I’ll read the crib sheet for online experiments.
Well I solved this problem by changing Keys to events:
event=psychoJS.eventManager.getKeys()
if 'space' in event:
wordNum+=1
thisExp.addData("Word"+str(wordNum),myClock.getTime())
myClock.reset()
if wordNum==nWords:
continueRoutine=False
So after that, there was another for thisExp which I changed into psychoJS.experiment.addData, but now it gives me another error for addData!
So I’m gonna ask you, which crib sheet of yours should I be looking at exactly?
Because the online one didn’t contain such information.
if wordNum>oldWordNum:
phrase+=words[wordNum]+' '
text.text=words[wordNum]
oldWordNum=wordNum
event=psychoJS.eventManager.getKeys()
keys=event.getKeys()
if 'space' in keys:
wordNum+=1
psychoJS.experiment.addData("Word"+str(wordNum),myClock.getTime())
myClock.reset()
if wordNum==nWords:
continueRoutine=False
Ps: the color code is not working. I’ll address it in another discussion of mine.
No, I’m not. Although I cleared cache when you said so. Still the same error
TypeError: Cannot read property ‘getKeys’ of undefined
And no! I don’t have getKeys anywhere else.
Here’s the entire code for my SPR. (and thank you again for the suggestions and responses of yours. I would have gone mad by now if it weren’t for your help.)
Okay. Thank you for the suggestion and I did remove line 6, but it’s becoming like a chicken-and-egg problem. Keys defined, events undefined; and the other way around.
TypeError: Cannot read property ‘clearEvents’ of undefined
I think maybe one of the issues is that you are using a single code component both at code_JS for Begin Experiment and Auto for Begin Routine and Each Frame.
I also note that you could have got confused about which line 6 I meant. I meant Begin Routine.
Please could you post screenshots of your code again.