| Reference | Downloads | Github

Conditional Stimulus Display

I am creating an experiment in coder in which participants either select yes (as indicated by pressing 1) or no (as indicated by pressing 2) in response to a question. Later in the experiment, I read their output excel file back into the experiment so that I can present them with the questions that they only answered yes to. I need a code in which if there is a 1 in the column called “yes_resp”, the question in that row will be displayed. So more simply put, I need the experiment to display specific stimuli from one condition based on another condition. I am at a completed loss on how to do this. I have uploaded my code, but if a more specific piece is needed, please let me know. I’m sorry if there are issues with my code, I’m relatively new to psychopy. (76.0 KB)


Hi Casey,

Realistically, people aren’t going to read 78 kB of Python code to try to answer a not-clearly-articulated question.

But in general I would suggest that you don’t bother with trying to read in an output file to get people’s responses. Just keep track of them in a list as you go: it will be much easier to deal with. It might be that you simply add the index number of the question on each trial if person answered “yes”, or the entire text of the question. But we really need more details explained to give you an answer: we can’t practically interpret your needs/intentions from the code.

thank you for your advice. I agree that it would be much easier to keep the items in a list as I go. Would you be able to elaborate more on this?

So for example, my participants answer yes if they would like to restudy the question, and no if they don’t. Then, later in the experiment, I want them to see only the questions they answered yes to. Would I have a larger loop encompassing the routine in which they decide if they would like to restudy and where they actually restudy. Also, would I put the code in the routine where they make the decision to restudy.

I’m sorry if I’m still not being clear. I’m having trouble articulating this in terms of coding.

Here is the code I wrote so far to start a dictionary. The only problem I’m having is I want it to keep track of not only the question, but also their response to study this question or not (‘y’ or ‘n’):

#begin experiment

Restudy = {}
allData = data.importConditions(u'practice.xlsx')
for dl in allData:
    scoreDict[dl[u'question']] = 0

#begin routine

studyagain = False
if Restudy[question] >= 2:
    continueRoutine = False
    studyagain = True

I’m also not sure of what to put in the end routine section.

Because you’re talking about routines and so on, I wonder if you are actually working in Builder vs Coder? It changes the approach one would take…

Originally I was in coder because that was the only way that I knew how to read back in the participant’s output files. This is the last part of the experiment that I’m programming so I had saved copies up to this point in builder and coder. Now that I’m no longer doing that, I went back to builder because it seems much easier to me.

I found someone doing something similar on discourse for builder, but I’m not sure if this is actually what I should be doing.

I can think of two approaches.

  • You could append the trial number of each ‘yes’ trial to a list. Then in a subsequent loop, you could read in the original conditions file again, but use the list of indices to specify the selected rows of that file. I’m not sure how this works when the loop is random, though.

  • You could append the question from each ‘yes’ trial to a list. Then at the end of the loop, write that list to a .csv file. Then in the subsequent loop, use that file as the conditions file.