| Reference | Downloads | Github

Show correct response

Hi, I am trying to show the correct response but my loop has 3 different conditions.
If the cue appears in the middle or both sides, or if there is no cue, the target may aleatory appear on the upper or lower monitor’s side. However, if the cue appears on top, the target must appear on top, if the cue appears on the lower, the target must appear in the lower part of the monitor.

I could not manage to get the correct answers, no matter what I press it returns as correct.

# All possible cues 
cuestim = {}
cuestim["blank"] = ImageStim(disp, size=(300,300), image="blank.png")
cuestim["centre"] = ImageStim(disp, size=(300,300), image="centre.png")
cuestim["upper"] = ImageStim(disp, size=(300,300), image="upper.png")  
cuestim["lower"] = ImageStim(disp, size=(300,300), image="lower.png")  
cuestim["both"] = ImageStim(disp, size=(300,300), image="both.png") 

tarstim = {}
tarstim ["upcongLeft"]= ImageStim(disp, size=(700,700), image="upcongLeft.png")
tarstim["upcongLeft"].correctAns    = "left"
tarstim ["upcongRight"]= ImageStim(disp, size=(700,700),   image="upcongRight.png")
tarstim["upcongRight"].correctAns   = "right"

tarstimup = {}
tarstimup ["upcongLeft"]= ImageStim(disp, size=(700,700), image="upcongLeft.png")
tarstimup["upcongLeft"].correctAns    = "left"
tarstimup ["upcongRight"]= ImageStim(disp, size=(700,700), image="upcongRight.png")
tarstimup["upcongRight"].correctAns   = "right"

tarstimdown = {}
tarstimdown ["downcongLeft"]= ImageStim(disp, size=(700,700),    image="downcongLeft.png")
tarstimdown["downcongLeft"].correctAns    = "left"
tarstimdown ["downcongRight"] = ImageStim(disp, size=(700,700), image="downcongRight.png")
tarstimdown["downcongRight"].correctAns   = "right"

# Create an empty list to contain the training trial
training = []
# Loop
for cueside in CUELOCS:
    for tarside in TARLOCS:
        for soa in SOAS:
            for tar in TARGETS:
                for tarsideup in TARLOCSUP:
                   for tarsidedown in TARLOCSDOWN:
                    # Training dictionary
                       trialtraining = {"cueside":cueside, "tarside":tarside,"tarsideup":tarsideup,"tarsidedown":tarsidedown, "target":tar, "soa":soa}
                # add the trial dictionary to the list
                       training.extend (TRAININGREPEATS * [trialtraining])
# Randomise
random.shuffle (training)

And this is the loop

for trial_, trial in enumerate(trials):
    if trial_ == 5:

    # Draw the fixation mark and the cues
    cueonset = disp.flip()
    wait (CUETIME)

    # Draw the fixation mark
    # Draw a target stimullus
    if cuestim[trial["cueside"]] == cuestim["upper"]:
        tarstimup[trial ["tarsideup"]].draw()
    elif cuestim[trial["cueside"]] == cuestim["lower"]:
        tarstimdown[trial ["tarsidedown"]].draw()
        tarstim[trial ["tarside"]].draw()

    # Wait for a response
    resplist = waitKeys (maxWait=float("inf"), keyList = ["left", "right"],timeStamped = True)

    # Select the first response from the response list
    response, presstime = resplist[0]


    # Check if the response was correct
    if response == tarstim [trial ["tarside"]].correctAns:
        correct = 1
    elif response == tarstimup [trial ["tarsideup"]].correctAns:
        correct = 1
    elif response == tarstimdown [trial ["tarsidedown"]].correctAns:
        correct = 1
        correct = 0

Whenever you are in a situation like this, insert some temporary debugging statements to check on what is happening compared to what you think is happening, e.g.

print('Response:', response)
print(tarstim[trial ["tarside"]].correctAns)
print(tarstimup[trial ["tarsideup"]].correctAns)
print(tarstimdown [trial ["tarsidedown"]].correctAns)

What does that tell you?

Thanks Michael,

I don’t know if I did It right but I had this as return (Example with 5 trials) :

Response: right
Response: right
Response: left
Response: left
Response: left

Your response is always going to be correct if it can only be left or right and is checked against three different answers which aren’t all the same.

Yes, I suspect that you have to add an additional and to your if statements: i.e. check whether the response is correct for a given sort of trial AND that this is in fact that sort of trial. That way, only one of the checks can evaluate to True, and you also leave the possibility that none of them will.

Thanks guys :frowning: