psychopy.org | Reference | Downloads | Github

Increase a number on each loop

Hi, everyone!

I’m trying to print the results the next format “Number_of_loop answer response_time”, sort of “1 correct 1.8373636”.

The following code used to work but now I’ve changed the experiment a little bit and it doesn’t. I was using this x variable starting with one to print it according to the response and increasing it by 1 after the printing. Now it prints hundreds of numbers (it’s just 26 loops). Does anyone know how to solve this?

Begin experiment

x = 1
clock = core.Clock()
soundfile = ['files/check.wav', 'files/blank.wav']
resultats = open('MiniMET melodia_resultats(' + expInfo['participant'] + ').txt', 'w')

Begin routine

clock.reset()

mouserec=mouse.getPos()
minRT = 9

Each frame

mouseloc = mouse.getPos()
if mouseloc[0]==mouserec[0] and mouseloc[1]==mouserec[1]:
    pass
elif correct.contains(mouse) or wrong.contains(mouse) or blank.contains(mouse):
     if t>minRT:
         continueRoutine = False
     else:
          mouserec = mouse.getPos()

if correct.contains(mouse):
    sound = soundfile[0]
    resultats.write(str(x) + ' correct ' + str(clock.getTime() - 9) + '\n')
    x += 1
elif wrong.contains(mouse):
    sound = soundfile[0]
    resultats.write(str(x) + ' wrong ' + str(clock.getTime() - 9) + '\n')
    x += 1
else:
    sound = soundfile[1]
    resultats.write(str(x) + ' blank ' + str(clock.getTime() - 9) + '\n')
    x += 1

Move your results code to End Routine rather than running it Every Frame

thanks, it works perfectly now!