In the book “Buiding Experiments in PsychoPy” by Jonathan Peirce et al., the authors discuss building a moving stimulus and the strength of the “t” variable that exists in Builder.
They describe as “t” providing a time in seconds since the current Routine started. When using it represent stimulus position, the notation (t,0) is used to change its horizontal position: When routine starts, stimulus will be at (0,0). After 1 second, (1,0). After 2 seconds, (2,0) etc. The authors build several examples utilizing this “t” variable to illustrate its versatility - however when I try it, I get the error “NameError: name ‘t’ is not defined”. Is there somewhere else in the builder where I can define it? Or is this an old feature that no longer exists?
Are you defining t manually anywhere? I’ve found that “not defined “ can mean defined twice.
I’m one of those authors, and yes, t
definitely (still) exists.
My guess is that you haven’t selected the appropriate updating option from the popup menu next to the stimulus position field. The t
variable gets initiated at the start of a routine, with a value of zero. If you want the stimulus position to update continuously, then you need to select “set every frame” so that the value is updated on every screen refresh.
If you have left it at “constant” then you would get the error you describe. This is because constant fields are set up at the beginning of the experiment (precisely because they never need to change again), but the t
variable hasn’t been defined at that stage, because the first routine of the experiment hasn’t started yet. So simply select “set every frame” and you should be in action.
You should never define or otherwise manipulate t
– that is something that the Builder script does for you automatically, and changing it in any way would upset the script in any number of ways.
Yes, T here is a time variable
Variables are case sensitive