TypeError: Cannot read property 'addData' of undefined + defining variables

Hello, I’ve been working on getting this memory task to work online. The url of the experiment is: Pavlovia and the repository is public.

On an earlier version of this project I was getting a lot of reference errors so I went in and started editing the JS file directly to define variables. I think this ended up creating more errors. Here is the question I posted then.

Now, I got rid of the import statements and worked on modifying the JS code so that the ‘translation’ is accurate. I didn’t edit the JS file after exporting it. I was able to upload this version, however when I tried to pilot it I got this type error. If anyone has insights on how to solve this I’d appreciate it greatly!

Have you got a thisExp.addData without having defined thisExp in code_JS as per my crib sheet?

(On phone so please search discourse for crib sheet to find it)

Best wishes

Wakefield

Hello @wakecarter
Thank you very much for your response! I made modifications (added psycho_JS component at the beginning and defined) and the url is https://pavlovia.org/lcdlab/center-spatial

This time when I synced and tried to run, I got a type error for the ‘addData’ component. In the beginning we define " thisExp=psychoJS.experiment; " but I also saw on the forum that we can type our code as “psychoJS.thisExp.addData” which is how I did it. Did I sort of double-dip or leave something out here?

If you do both of what you’ve written above then you will end up with

psychoJS.psychoJS.experiment.addData

On the other hand a manual translation to psychoJS.experiment.addData should be fine

Thank you! I suspected I was duplicating the command. So I got rid of the additional “psychoJS” in the addData lines and just defined it in the beginning. I synced and now when I try to pilot it this time I get a different type error that “trialType” is not defined. My understanding was that psychopy defines these variables. Do you have any ideas on why this may be happening?

Whenever you get x is not defined add x=0, ‘’ or [] as appropriate in Begin Experiment. JS has different rules.

1 Like

Great! Thank you very much for all your help, I appreciate it a lot!
I’ve defined most of my variables but the trial count seems to be a problem. (I have three total) I saw on the forum that you suggested to use different variable names, but how I had it set up was setting eTrials (encoding trials) to 0 and then at the end of the routine setting it to eTrials + 1.

Right now, if I set eTrials= 0 in the beginning of the experiment, I get an error saying I can’t do this during intialisation. If I define it as “var eTrials;” then when I set it to eTrials = 0 in the routine I get the error ‘Identifier eTrials has already been declared.’ Am I using the wrong type (identifier vs variable)?

I would just type eTrials = 0 in the Python window which should auto translate to eTrials=0; (no var)

At the end of the routine you need to put (in Python) eTrials++