psychopy.org | Reference | Downloads | Github

Randomizing the position of text stimuli

Hello everyone,

I’m trying to randomize the presentation of stimuli by altering the position of three texts with three different locations. During the experiment, a sentence will be followed by three texts (e.g., ansA, ansB, ansC) in which their positions will be presented in a random order. The three texts are listed on each column in Excel file.

I read several posts dealing with this topic and based on these posts I put some codes in Begin Routine as below:

To randomize the order on each trial:

positions = [[-0.6,0],[0,0],[0.6,0]]
shuffle(positions)   

To create a dictionary which maps keyboard responses to their corresponding x coordinate:

key_to_x = {‘z’:-0.6, ‘v’:0, ‘m’:0.6}

To indicate the x coordinate of the chosen stimulus:

thisExp.addData(‘chosen_x’, key_to_x[Choice.keys[0])

Additionally, I input relevant attributes in Position and Text on each object (e.g., $positions [0] and $ansA, respectively), all by set every repeat.

However, the builder doesn’t run. I also put these codes in End Routine because in earlier posts it was recommended to put them in this section, but neither of them works.

What would be wrong with that?

Thank you in advance for your help.

That doesn’t tell us much useful. Are there error messages generated?

The key to understanding code components is to think when the code ends to run:

  • If you are setting the position of stimuli for a given trial (as in shuffling your positions variable), then that code needs to run in the “Begin routine” tab, otherwise the stimuli won’t be displayed in the right place.
  • If you are creating something that won’t change throughout the experiment (like your key_to_x variable), then it can be defined just once, in the “Begin experiment” tab.
  • If you want to record what happened during a trial, then that code only makes sense to be in the “End routine” tab.

The ‘Run’ button on top of the screen itself doesn’t work whenever I try to run the program.
Is the problem due to the version that I installed or my own computer?