Making a Variable Number of Stimuli Appear on Screen

As suggested in the title, I am trying to make a variable number of stimuli appear on the screen. Each trial I need a different (random within a range) number of squares to appear. (Five squares on one trial, seven squares another trial, etc). The trouble is I need them to all be presented at the same time.

I tried inserting a square stimuli, placing variables for the x and y coordinates, inserting a code block to manipulate the variables, and placing it in a loop repeating a variable number of times to get a different number of squares in each trial. This didn’t work because it won’t enter the next iteration of the loop until a routine is finished. This means I either have to give the stimuli a duration or choose an event to end it, both of which make the square disappear before it can formulate the next one. Is there a way for a routine to end but still leave its stimuli on the screen? Or is there a simpler way to build this so that the number of squares presented changes with each trial?

Thanks in advance for any help :smiley:

  • What is the range of the number of squares (i.e. minimum and maximum)?
  • What are the positions of the squares? e.g. do they vary or are they fixed? If they vary, in what way?

Thank you so much for the willingness to help. To answer questions - the range of squares is 5 - 9, spread between 12 possible positions. The possible positions are fixed, but which are filled is variable.

I was able to get my code to work. There is probably a more elegant solution, but this is what I came up with in case it helps anyone in the future.

In a coding element, I made a list of all the indexes for the potential twelve positions. Every trial, a randomly selected three and removed them from the list. I then created 9 squares and set their positions equal to positions 0 - 8 on the list. To allow me to have a variable number of those nine squares appear, I also made a list of opacities and set each square’s opacity equal to the matching position (0-8) on that list as well. I would then select random squares based on the number I needed (none if I needed 9 squares to appear, 4 if I needed 5 squares to appear, etc) and set their opacity to 0. This allowed me to have between 5 and 9 squares appear depending on the trail.