Jdigg
December 18, 2025, 2:10pm
1
Using the latest version of Psychopy. URL for experiment is here: https://run.pavlovia.org/JDiggins/sart2
There is code in within the experiment which uses the .rt from a keyboard command, however this causes a crash and from what I can see it’s because Pavlovia is not recording the reaction times.
Is there a tickbox I am missing?
Jake
I think you are misunderstanding the error message
TypeError: Cannot read properties of undefined (reading ‘key_resp_3.rt’)
The error is from meanRt = trials.data["key_resp_3.rt"].mean();
so trials.data is undefined. If the rt was missing it woudl be a key error instead.
What I do is append the RT to a list (when correct) and then calculate the median of that list rather than trying to access the data frame.
Jdigg
December 18, 2025, 2:40pm
3
I now have it appending the .rt to meanRT as a list. I then have meanRt = meanRt.mean() but it is returning that .mean is not a function.
Jdigg
December 18, 2025, 2:52pm
5
So I have changed it to that and I am now getting KeyError: math is not defined.
I’ve just checked and math is Python. Math is JS, so you could try Math.mean
As I mentioned, I normally use median, but in one experiment I defined an average function in a JS component.
average = function(data){
var sum = data.reduce(function(sum, value){
return sum + value;
}, 0);
var avg = sum / data.length;
return avg;
}
Jdigg
December 18, 2025, 3:38pm
7
I think I’m getting somewhere (I hate JS!) so I have it plugged in as meanRt = average(meanRt), after declaring your function at the beginning of the experiment. The experiment now runs through but I get “NaN” as an answer.
I don’t like working in JavaScript either. Here’s a simpler function which should work that Auto translates. Note I’ve put it in Before Experiment
def average(x):
return(sum(x)/len(x))
Try printing meanRt to check it’s a list of reaction times.
Also, I would recommend using separate variable names, e.g. meanRT = average(listRT)
Jdigg
December 18, 2025, 4:00pm
9
Brilliant, that’s all fixed now.
I added a rounding to the function as well just for ease.
Thank you
1 Like