psychopy.org | Reference | Downloads | Github

Continuously updating text stim on specific frame gaps

[ Using Standalone PsychoPy on Windows 10. Builder View ]

Hi everyone,

I’m working on an experiment which requires to display a text character on screen during very short time gaps (20 frames each).
So I’m using a single text object, which gets the value of the character supposed to be displayed on a custom code, provided as follows:

[ Begin Routine section ]

 txtset1 = ["A","B","C","D","E","F","G","H","I","J","K","L"]
 txtset2 = ["A","B","C","D","E","F","X","H","I","J","K","L"]
 txtrand = randint(1,10)
 if txtrand > 2:
     letras = txtset1
 else:
     letras = txtset2

[ Each Frame section ]

 aux = randint(0,len(letras))
 chosen = letras[aux]

“Chosen” is the name of the variable set on the Text object, so it is the one being updated on each frame
The issue here, is that setting this “on each frame” is way too fast for this experiment. As said before, each character is expected to appear on screen during 20 frames. For example, during the first 20 frames any random character from the list should be displayed, then another random character during the next 20 frames and so on.

There is no option for setting the value for custom durations, so I thought of asking for help here.
A friend suggested creating a text object for each and one of the available characters, but that’s not exactly optimal, specially when the character list increases, so I’m aiming to solve this using a single text object.

Still, I don’t have any problems using the Coder View, so if you suggest a solution which requires that View, I’ll be glad to hear about it too.

Thanks in advance.

You want to cary out the letter selection only on every 20th frame. You can do this using the modulus operator:

if frameN % 20 == 0 # on every 20th frame 
    aux = randint(0,len(letras))
    yourTextComponentName.text = letras[aux]

Don’t use a variable (i.e. chosen) here, as it will be needlessly updating the text stimulus on every frame, even though it isn’t changing. Instead, set it to have some constant value (e.g. XXXX) and change it in code as above, which will only happen on every 20th frame. XXXX should never appear on screen, as the component should update on the first frame (when frameN == 0, so the remainder of dividing it by 20 is also 0). Make sure that the code competent is above the text component (a brief flash of XXXX will show that it isn’t), so that the text competent gets the new value before it re-draws.

1 Like