| Reference | Downloads | Github

psychoJS.experiment.addData doesn't work

URL of experiment:

Description of the problem: I know that is a common problem, and a lot of stuff has been posted on how to solve it, but I tried everything I’ve found, and nothing worked.
I’m working with the builder, and I want to add the array contining the order of the images in each run of the loop, called images, to my output file in Pavlovia.
This array is redefined at the begin of each loop (at the Begin Routine of a code block) and it is a general variable, thus I declared it without specifying the var in JS.
I used psychoJS.experiment.addData('images', images); to save in the End Routine of the block, but it does not work: when I run the Pilot experiment, there is no ‘images’ column.
I tried to use both the name of the loop (trials.addData('images', images);) and of the experiment (trial.addData('images', images);) instead of it, but nothing worked…
Do you have any suggestion?

I’m guessing here but I think is not possible just to pass an array to the addData function. Did you this?

psychoJS.experiment.addData('images', images.toString());

I tried, but it’s not that. I even tried something simpler: just adding a constant variable to the output. I thus inserted this in the End Routine of the code block:

a = 5;
psychoJS.experiment.addData('images', a);

It isn’t working, either. I really can’t understand, it doesn’t throw any error…

@michele_conni, it will be useful to see your experiment structure to see why the data is not being saved, but it may be that there needs to be a call to psychoJS.experiment.nextEntry(). This should happen automatically in loops, but not sure why the data is orphaned here without seeing the experiment, and where the data is being saved.

@dvbridges In my experiment, the observers are asked to select similar images inside a selection of figures. I have an introduction, a code section in which the images are randomlized and picked, a trial section in which they are showed to the observer to make her/him select the similar ones and an ending step.
This is the structure of my experiment:

In the Begin Experiment step of code_1 I defined a list of positions of images:

and in the Begin Routine one I shuffled the list and exctracted a smaller array, images:

In the trial step I then defined 26 image objects, which load the elements of images:

Now, the output saves the name of the objects clicked with the mouse, but I wanted to save images, too, because includes the actual name of the images selected by the observer. This is the current output I get from Pavlovia: output.csv (646 Bytes)
In the question there should be the link to the code I am using.
Where should I insert psychoJS.experiment.nextEntry()?

Try putting it after your call to addData, but remove those other calls including trials.addData. If this works, it would be good to figure our why it failed in the first place.

Thanks! I tried, but it doesn’t work… I really don’t understand, it seems like it’s ok, the JS file uploaded to Pavlovia is right ( and the same line is used afterwards to successfully save the other columns… Could be that it is overwritten?

Strange: I tried to comment the other psychoJS.experiment.addDatas, both in trial.js and in trial-legacy-browsers.js, but the outcome of the pilot is the same… Could be that Pavlovia is loading an older version of the code?

Ok, now it is working, there was some delay in the application of the corrections in Pavlovia’s pilot. Thank you very much @dvbridges! I guess that the initial problem was the lack of psychoJS.experiment.nextEntry()