0

Here is my code (though incomplete):

for k in range(len(ace)):
    recognitionstim.image = ace[k]
    old.draw()
    new.draw()

    if ace[k] in ac:
        recog = 'old'
    else:
        recog = 'new'

    win.flip()
    trialClock.reset()
    resp = event.waitKeys(keyList = ['a','l'])
    rt2 = trialClock.getTime()


    if resp == 'a' and recog == 'old':
        accuracy = 'correct'
    else:
        accuracy = 'incorrect'


    writer.writerow([k,ace[k],rt2,recog,resp,accuracy])

What this code does is it shows a series of images, and if they came from the list titled 'ac' they will be called 'old.' What I'm trying to do is write code that takes things that are 'old' and pairs them with a key press ('a') so that if old and 'a' is pressed it will log it as 'correct'. However, it doesn't appear to be able to read 'recog'. Any ideas on how I might fix this? Any help will be greatly appreciated. :)

Philipp Wendler
  • 11,184
  • 7
  • 52
  • 87
y3trgfhsfgr
  • 467
  • 8
  • 17
  • 2
    I assume that you get no error messages when you run this? If you do, please post them here. Try printing various variables to make sure that they have the values you think they have. For example, is ``ace[k]`` ever in ``ac``? Try printing them just before the comparison and see. – Jonas Lindeløv Mar 02 '15 at 19:46
  • Thank you for your advice, printing made me see my error - I actually needed to write ['a'] not 'a'. :) – y3trgfhsfgr Mar 02 '15 at 20:40
  • 1
    So you need to exactly as Jonas says. Scatter print() and print(type()) statements everywhere to see what is going wrong. For example, resp will often be a list like ['a'] rather than a single string like 'a', which could cause that comparison to fail. [I see you did exactly that about 2min ago :-) but now I can't delete this comment.] – Michael MacAskill Mar 02 '15 at 20:43
  • 1
    Posted an answer, just to keep the Q&A format. – Jonas Lindeløv Mar 03 '15 at 20:56

1 Answers1

1

event.waitKeys returns a list so resp is a list. Instead of comparing to 'a' you should compare to ['a']:

if resp == ['a'] and recog == 'old':
    accuracy = 'correct'
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54