Javascript replacement for globals()

URL of experiment:

Description of the problem:
I use the following code to save the data I need:

a = (globals()[loopNameF])
a.addData('corr.Ans', corrAns)
a.addData('part.resp', mycorreResp)

where “loopNameF” is a column read in from a csv file.

It works fine on psychopy but breaks on pavlovia with this error:

ReferenceError: globals is not defined

I’m guessing this is because I cannot use globals in javascript, so I am wondering if there is another way to accomplish the same thing, or something similar to globals in javascript?

I’m afraid I can’t run your experiment to take a look (the pilot token expired), but I do have a guess on what might help:

At the being routine tab inside of the loop, write:

psychoJS.addData('corr.Ans', corrAns)
psychoJS.addData('part.resp', mycorreResp)

Note that this is just a guess, but a somewhat informed guess :slight_smile:

Unfortunately, that does not appear to work. I tried putting it in multiple different places and get the error:

TypeError: psychoJS.addData is not a function

Sorry, my mistake. The correct function should be:


I’ve got two other pointers that could help your experiment:

  1. I noticed that some of the images are rather large files (BMP files of 12MB). That can be very heavy on less modern computers and affect your timing accuracy. I recommend recoding them to PNG (or JPG for even better compression)
  2. In a web-browser, you can log debugging info via the statement below. These will be printed to the browser console. In Chrome and Firefox the console can be opened via F12, though all major browser offer it.
console.log("this is a debug message")

THANK YOU!!! That seems to have fixed it.

And thank you for your other pointers, I appreciate any advice/help I can get! I’m working on implementing those now.

1 Like