psychopy.org | Reference | Downloads | Github

Online experiment - cannot read property '0' of undefined

Description of the problem:

My experiment involves clicking on a images. I have a code component where if the answer is correct, 1 will be recorded and if it’s wrong, 0 will be recorded.

Untitled1

Untitled2

When I run the experiment through pavlovia, I got this error

As far as I know, the [0] acts like a placeholder and if I remove it, I will get a syntax error. I am not sure how to modify my code so that it will run online.

I am using psychopy v3.1.5

Hi @suelynnmah, I cannot see any JS code, have you converted your Python code to JavaScript? If you go to your code component, you can select a code type of “JS” for JavaScript, or “Both” Python (left) and JS (right). The code translation of code components is not automated yet, so for now you have to translate the code over manually. Let me know if you have any issues.

hi, so when you say manually, do you mean i have to write the jscode by myself?

Yes, but it is not so different from Python. E.g., your code above as JS:

if (mouse.clicked_name[0] === S1correctAnswer) {
  psychoJS.experiment.addData("S1correct", 1);
} else {
  psychoJS.experiment.addData("S1correct", 0);
}

If you have any issues, we can help.

So i have changed the setting into js and copied the code

Unfortunately I still got the same error message. I double-checked that I have synced the experiment so I’m not sure what went wrong.

Would you mind sharing the URL for your task, so I can take a look at what is happening?

sure but where is the url?

You can copy and paste the address from your browser when you attempt to run the study online.

https://run.pavlovia.org/suelynnmah/fattest/html/?__pilotToken=57a3d033a9a32c0c2c5b1d930dbb2a77&__oauthToken=24c659689bc1cda1cb15c24cdd0ef54100adc2b909cd1714dc640f6d4c6e3102

@suelynnmah, would you mind generating another pilot study? The links are only active for one hour when piloting your tasks.

Also, have a look at your Test.xlsx file. I think there are some empty columns and rows that will cause this error. Try deleting your empty columns (D and E) and delete row 10 of your sheet. Save this, resync with Pavlovia and try again.

yes i have deleted the rows and columns in my test.xlsx file and still got the same error

https://run.pavlovia.org/suelynnmah/fattest/html/?__pilotToken=94cee6481e815f6f98d68cc704a57cb9&__oauthToken=24c659689bc1cda1cb15c24cdd0ef54100adc2b909cd1714dc640f6d4c6e3102

This is an issue with the clickable image stim not having a size defined. To detect that the image contains the mouse and has received a click, a size needs to be defined (although that is not explicitly stated). I will have a look at getting a fix implemented, but in the mean time you should be able to fix your error by giving each clickable image a size e.g., set the size the the image stim to [.5, .3].

I have tried changing the size of the image stim and unfortunately have the same error

Can you try refreshing your browser (Shift and F5 if on Windows) and try again? The fix should solve your issue, at least for your image stim called A and B.

I have refreshed, and closed the tab and opened it in a new tab but it still does not work

Ok, well this is your current code: https://run.pavlovia.org/dvbridges/test/html/

This appears to be working, when I click the buttons they change colour and no errors appear. Is the error related to something else? Are you getting the “pilot token” error instead? If the error is really the same, clear your cache in your internet history in your browser settings and try again.

Yes my experiment is now working when i run the pilot from pavlovia. But when I run it from builder mode, it is giving me the “pilot token” error. I assume it is because I don’t have tokens?

It is because Builder is not currently set up to run pilot studies, you have to run them from Pavlovia. Each pilot session run from Pavlovia provides your task with a pilot token, which is valid for 1 hour, and during that time you can run the task for testing. You can create as many pilot tokens as you need. If you change the status of the task on Pavlovia to “RUNNING”, you can run from Builder. This is free until 1st October.