Adding information about a trial to an array on Pavlovia

Hi all,

I’m collecting information about my trial in a list called myList (this list is then used to do some further processing). In Python, at the end of each trial, I’m appending information about the letter presented on the current trial like this:

myList.append(thisTrial["letter"])

In JavaScript, this does not seem to work, even after adding the name of the loop (i.e., trials) before thisTrial as suggested in another forum post:

myList.append(trials.thisTrial["letter"]);

I get the error message “TypeError: Cannot read property ‘letter’ of null”.

Given that I don’t really know anything about JavaScript, I’m at a loss at how to fix this issue.

This is a minimal example illustrating the issue.

Any help would be greatly appreciated.

Jan

Hi there,

Is ‘letter’ set using a column in a conditions file? if so, you can just use myList.append(letter) instead. Please note that for use online you would need to set your codeType to be ‘both’ and on your JS side change this to be myList.push(letter)

Hope this helps,
Becca

Thanks, Becca! I can confirm that this works. I initially used Auto->JS and this produced append on the JavaScript side. Should this be push then?

Jan

1 Like

Yes - append is ‘push’ in JS - pleased it worked :slight_smile: