If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Win10 PsychoPy version (e.g. 2024.2.4 Py 3.8): 2025.1.1 Standard Standalone Installation? (y/n) If not then what?: y Do you want it to also run online? (y/n) n
I am trying to add a jittered inter-trial interval to my experiment in builder. I have used some code from another post on this forum, and there is no syntax error in the code itself, but when I try to pilot the study I get a TypeError saying ‘can’t multiply sequence by non-int type ‘float’’.
jitter = [random() * [500 + (486)]] #add jitter
jitter = round(jitter, 1) #round to 1dp
thisExp.addData('jitter', jitter) # add 'jitter'column to data spreadsheet
This is the code I have used, in a routine before my main task routine. Any help on how to fix this would be much appreciated!
random() returns a number between 0 and 1. What would you expect jitter to look like if random() returned 0.5? Are you using square brackets (which denote a list) when you mean parentheses?
Thank you for your response! I didn’t realise random only worked between 0 and 1, I thought it returned a random float (as opposed to randint()). If it returned 0.5 I would assume a jitter of 493ms.
You were right about the square brackets - using parentheses stops the error, but there is no jitter occuring.
There is a jitter column with one value at the top, but no jitter for the rest of the trials - I am aiming to have a different interval for each trial but there is no data in the rest of the boxes.
I will keep it in ms, and round to the nearest ms as you suggest.
The code should be in a Begin Routine tab if you want to change it every iteration. It sounds like you either have it in Begin Experiment or in a routine outside your trials loop.