Well, JS code errors on Pavlovia

No no no. I am using Auto==>JS for all sections. I sent you a screenshot of JS code for the first two parts because well, that’s what matters in Pavlovia, JS codes. And for each frame i sent auto/JS because JS codes for this part were simply too long, so you know.
And yes, you were right. I confused it with line 6 of each frame. Now that I saw your message, i fixed it though, run it again and surprise surrprise:

  • TypeError: Cannot read property ‘getKeys’ of undefined

Here are the screenshots:

1
2

Bests,
Zeinab

I think that the auto translate might be getting confused because the Begin Experiment code is supposed to be on the JS side only – please put it in a different code component which is JS only.

Thank you. I did that too. Still the same error about getKeys undefined.

Does anything else seem wrong to you? I would have removed the useless codes for the color, but it’s not what causing the problem here, and I don’t get it.

To get a better idea of what causes the error message, see this tutorial: Thomas Pronk / tutorial_js_semantic_error · GitLab

Dear Thomas,
thank you very much for this. So i read the tutorial - though I already knew how to find the error in console - but rechecked it tonight. Click inspect, Console, find the error with the the experiment’s file and then: 404 Not Found.

But you know what? this is not a problem. Because I know exactly which line is causing the error in the Builder view. what I don’t have a clue is what to do after finding the problem, how to solve it. thank you for your time thomas but do you know any tutorial or solution for that? :slight_smile:

Please could you upload your psyexp file here? I feel like the only possibility is that you haven’t yet managed to put the definition in the right place.

Hi. sure!
Demo3,a.xlsx (12.6 KB) selfPacedReadingTask(A).psyexp (36.0 KB) selfPacedReadingTask(A)_lastrun.py (23.3 KB)

Cheers,
Zeinab

The psyexp file you sent contains all JS only code components instead of Auto apart from JS only for defining win and event (code_JS as per my crib sheet).

It includes the line event = psychoJS.eventManager.clearEvents();

which will lead to an error when it gets to keys = event.getKeys();

I also suspect that you will have an issue with the comma in the Excel file name. I would recommend an underscore.

dear @wakecarter, let me give a recap to ensure that I’m following you.

So the default must be Auto ==> JS? I thought Pavlovia runs with JS codes better, but anyway. So here’s the message i receive for changing it back to Auto
pj
Is that okay to press OK?

So the only codes that are in line with Auto are the event and win code? (win code doesn’t apply for color here)

I’m a little bit confused. I read it over and over but still confused. I checked your crib sheet

This one. I wrote the codes you suggested in the very first lines of document in the Begin experiment section, and I reviewed it again but there was no code for event and keys. I’m so lost.

Regards,
zeinab

You’ve linked to my code snippets page rather than my crib sheet. However, at the top it says:

Code components should be Auto Py->JS unless code has been added to the PsychoJS column. I would recommend that all experiments intended to run online contain a JavaScript code component in their first routine called code_JS with the following in Begin Experiment.

thisExp=psychoJS.experiment;
win=psychoJS.window;
event=psychoJS.eventManager;
shuffle = util.shuffle;
Array.prototype.append = [].push;

Please do tell me if there’s something in that paragraph that needs further explanation.

When changing from JS back to Auto I would recommend copying the JS code to the clipboard, then agreeing to overwrite it, then pasting it into the Python side and finally formatting it as grammatically correct Python code such that auto translated JS code appears on the JS side.

Dear @wakecarter,
yeah it was crystal clear, the instructions and I followed the steps, read the actual crib sheet and here’s how my codes look now:
Begin JS
2


and I read the discussion you attached esp. this part I could relate to:

So here’s my one and only question. Because I followed your instructions, cleared the cache even but still I receive the same error about getKeys. Where should i define Keys exactly? should i remove this line or what?
I read your crib sheet and there was a tip for how to clearEvents but I did not find anything related to Keys. How do I solve this problem? I do appreciate your help.

Cheers,
Zeinab

Given that you’ve failed to create a separate JS only code component for code_JS and have auto translated core.Clock() I’d expect you to get a clock related error, not an event or error. Please could you show a screenshot of your error message?

How come? so after rewriting the code in auto, I should change it to JS again?
And no, it’s the same error:

  • TypeError: Cannot read property ‘getKeys’ of undefined

Best,
Zeinab

These lines should be pasted into a new empty code component which has already been set to JavaScript only. They should not appear in an Auto component.

Morning!
JS
Still the same error. Do you think i should build a new project? and copy everything there with a JS code default?