Randomising Stimuli Duration

OS (e.g. Win10): macOS 13.5.1
PsychoPy version (e.g. 2024.2.4 Py 3.8): PsychoPy v2024.1.5

Hi there! I am trying to randomise the duration that a stimuli is presented. For a little context, I’m trying to set my experiment up in a way that makes participants decide quickly between imageA and imageB. If they do not make the decision in 28 frames, they will be prompted to make their decision faster in a different routine. If they do make the decision on time, the experiment will skip the next routine and move to the next trial (repeat the routine). My current flow in my single routine is:

polygonFixation (60 frames) → imageAScrambled (2 frames) → imageA (x frames) → imageBScrambled (2 frames) → imageB (x frames) → imageBScrambled2 (2 frames)

x should be assigned 2/6/12 frames.

I set each component to begin when the previous component ends. For example, when imageAScrambled is supposed to begin, the start is specificed as “$polygonFixation.status==FINISHED”. Additionally, after imageBScrambled ends, a text and a key will also start for 28 frames (to prompt the decision making). That means that it should continue displaying even if x < 28 frames.

When x is preassigned to the image pairs, the experiment works perfect. However, we preferred to randomise them fully.

I first randomised the presentation times through Excel with column “frame” and value “$[2,6,12][randint(3)]”. However, I think PsychoPy is processing the input as a string and thus the experiment keeps crashing.

I then tried to use code to randomise it (I’m still new to Python, sorry for any mistakes!).

Begin experiment:

import random
allFrames = [random.choice([2, 6, 12]) for _ in range(15)] # 15 trials
random.shuffle(allFrames)

Begin routine:

currentFrame = allFrames.pop(0) #take and remove the FIRST item from the list

Currently, the randomisation works well, but the text and key disappears. The data output also recorded the start and stop time of these two components as exactly the same (i.e., as when imageBScrambled ends).

I appreciate all the help I can get (preferably with as little code), and happy to provide more context if necessary. Been working on this problem for a few weeks now :confused:

Hello @finn

You could convert the string to an int.

ranInt = int("10")

See here How to Convert a Python String to int – Real Python

Best wishes Jens

Hi Jens,

Thanks for the suggestion! I tried using several methods to ensure that it is being read as an integer, but when it runs, the prompt for text and key disappears with same start and stop time again (similar issue as to the above).

Best regards
Finn

Hello @finn

You will need to provide more information about how you programmed your experiment.

So how do you try to do this? In which version does it work, and in which does it not?

Best wishes Jens

Since allFrames is shuffled why use pop(0) rather than just pop() ?