Javascript replacement for globals()

URL of experiment: https://run.pavlovia.org/utahmend2lab/fept_mr_touch_eng_v1/html/?__pilotToken=b6d767d2f8ed5d21a44b0e5886680cb9&__oauthToken=8e3a90791a8681fedd9f0316076bce1f4aee2c4a3aeb0f990cfc4498489e4b71

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:

psychoJS.experiment.addData

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