Stroop test - how do I assign letters to the colours?

Hi all,

I am very new to coding and I have been set the task of creating a stroop test using code in psychopy.
The requirements are that I need to code for 1 trial of a modified stroop task experiment, using coder.

  1. I have an initial frame of introduction, to explain to participants what they are expected to do, then they can start the experiment once they are ready by pressing any key.

  2. I am stuck on the word ‘green’ coloured red appears on screen, till participants respond with a key response. Allowed keys are: r for red, g for green, b for blue and y for yellow. I then have an inter-trial interval. I have tried:
    MyColor = random.choice([‘red’,‘blue’,‘green’,‘yellow’])
    Phrase = random.choice([“red”,“green”, “blue”, “yellow”])
    time = str(datetime.datetime.now())
    key = str(event.getKeys(keyList=[‘r’,‘b’,‘g’,‘y’], ))

But this is not working. It is running through the words and word colours randomly without accepting the keys :weary:

  1. I am unable to record participants’ response and participants’ reaction time, it is saving something to a Test Output csv file but it doesn’t seem to have anything to do with my interaction with it.

I have really tried looking on the web and through books but I am really stuck on these points. Please help!

EDIT: I have changed getKeys to waitKeys and now it seems to accept some key input, not all the time though!? Which is strange :face_with_diagonal_mouth: So it just recording response and reaction times, if anyone could help with this I would greatly appreciate :pray:

Are you using Coder because it’s for a course?

Getkeys checks whether a key has been pressed but doesn’t stop, so it needs to be in a loop if you want to allow a fixed time to respond. Wait keys stops the processing until a key is pressed.

Thanks so much for your reply. Yes, it is a course in which I have been set this task.

Ah, I see, so getKeys would probably be more useful to me then, but with the key input, I am trying to assign r for red, b for blue etc, and it isn’t accepting all of them, so should this be getKeys as well?

key = str(event.waitKeys(keyList=[‘r’,‘b’,‘g’,‘y’], ))

I’m so confused. Thanks for your help!

EDIT: I tried and waitKeys works better here, I can see it in my .csv file

key should be getting set with the key pressed. You then need to compare this with the key expected.

If you random choice from a list of 0 to 3 then you can use this value to pick the same colour and correct key from unshuffled lists. Alternatively, use two dimensional lists.

1 Like