psychoJS.experiment.addData() doesn't save variable

URL of experiment:

Description of the problem:
Dear all,

In my experiment I have to generate random numbers from 0 to 100. I used Math.floor(Math.random() * 100) to generate the numbers. I want to save the numbers that were generated. In Python version on my computer I used thisExp.addData(“result”, result) and in online version I used psychoJS.experiment.addData(‘result’, result), where result is the randomly generated number. The version on my computer works and saves the numbers, but the online one doesn’t. Do you know how can I fix this?
Below I attached the Psychopy file.
third.psyexp (9.4 KB)

1 Like

Hi @sramo, I think the issue may relate to how you declare your variables using var. You do not have to declare JavaScript variables in PsychoPy, because psychopy will do this for you, declaring the variable with global scope. Currently, the result variable is limited in scope to the beginning of the trial routine. To fix, remove the var from the result variable.

1 Like

Hi @dvbridges, thanks for help. It works now.