How do I set a random start time for my choices?

If this template helps, then use it. If not, then just delete and start from scratch.

OS (e.g. Win10): macOSCatalina
PsychoPy version (e.g. 1.84.x): PsychoPY v2021.1.4
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I try to experiment with testing people’s short-term memory, but I need the time between the stimulus and the presented choices to be random from 5 to 20 seconds with a 5-sec interval. How can I achieve that with the code component?
What did you try to make it work?:
I tried to use the code component.
What specifically went wrong when you tried that?: As you can see, I have my stimuli presented for 0.5 seconds, and after an interval of time, I will show the participants the possible choices to see if they recognize what they saw.
I want to make the intervals random from 5 to 20 seconds with a 5-sec interval. I am completely new to PsychoPy, and I am not sure how to achieve that.
Include pasted full error message if possible. “That didn’t work” is not enough information.
I do not have an error message yet since I have no idea how to do it, but I do have a screenshot of my GUI, shown below:

Thank you so much!

Hi,

When you say 5 to 20 seconds with 5 seconds interval, do you mean the start time being either 5,10,15 or 20? That is my assumption for now.

Add a code component and move it to the top by right-clicking the code components name in Builder view. Add the following code in Begin routine:

time_choices = [5,10,15,20] 
offset = 0.5 # "delay" from imageTraining component

# randchoice() returns on of the start times from the list above randomly.
start_time = randchoice(time_choices) + offset

In the components you now add $start_time in the start slot of the image components. $ means it’s a variable.

Hope this works :smile:

Thank you for replying so quickly!

However, a syntax error returned. Here is the error message:

Running: /Users/athenahuang/Downloads/CIS Experiment/CIS_2_lastrun.py

60479.3276 INFO Loaded monitor calibration from [‘2021_05_29 04:09’]
File “/Users/athenahuang/Downloads/CIS Experiment/CIS_2_lastrun.py”, line 438
if imageChoice1.status == NOT_STARTED and tThisFlip >= $start_time-frameTolerance:
^
SyntaxError: invalid syntax

Experiment ended.

And here is what I have tried:
for the code component, I have:

for the image I have:
image

Could you please let me know where I have gone wrong? Or please let me know if there is another thing I can provide for your inference!

Thank you so much!

Seems like it may accept variables by default. Try removing the dollar sign and just type start_time in the field.

I have removed it,
image

but it still showed:
image

Should I try restarting PsychoPy?

Thank you!

Make sure to send your experiment again to the runner by pressing the green play button, so that the code gets updated. Seems like it ran your old code again.

It worked!!! Thank you!

1 Like