Cannot read properties of undefined variables

If this template helps then use it. If not then just delete and start from scratch.

URL of experiment: - Adam Manoogian / physics_debug_v3 · GitLab
Do you want it to also run locally? (y/n) y
What are you trying to achieve?:

I’m facing the common cannot read properties of undefined error when I try to run my experiment in js (it works in python). I’m drawing from the cue_and_mouse example from the demo, and trying to update my columns on each loop (to decide a path of cue position coordinates) and exact coordinates from each row on each frame.

Unfortunately it gets caught on the first call in the begin routine and cannot find the variable online.

What did you try to make it work?:

I tried calling the variables differently, assigning them in ‘before experiment’, and assigning them to the cue in the format consistent with the cribsheet.

I cannot figure out how to diagnose if my spreadsheet is even being loaded correctly, or if I’m just not calling the variable correctly.

Apologies, I realize this is a common error, but cannot figure out how to apply others’ fixes to this case where I’m trying to index into the correct condition variable.


As per Wakefield's Daily Tips - #100 by wakecarter you should focus on what is undefined. In your case I think it’s trialIndex. Try putting print('trialIndex',trialIndex) on line 3.

I haven’t had any experience with .getFutureTrial, so I suspect that that’s the issue. It could be simply that you need to remove the quotes from around “n”. I’ll report back here if I get a chance to investigate.

Hi Wake,

You’re correct it was undefined upon printing.
I’ve just fixed the indexing from the auto py → js from:

myPaths.getFutureTrial({“n”: triggered_frameN});

to:

trialIndex = myPaths.getFutureTrial(triggered_frameN);

and that fixed the problem.

Just to note, the auto translate didn’t work for the each frame code as well, so it was changed to

Thanks again!

1 Like