PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) Y
For my experiment I need to include a variable that is the sum of the number of correct answers in the last ten trials to calculate the points for each trial.
In order to do this I created a trial number variable using custom code in the trial routine (begin experiment: trialN = 0. End routine: trialN = trialN + 1). I displayed the trial number to test if it is working and it is working fine. However, I can’t get my trial score and total scores in the feedback routine to work.
In the feedback routine I am attempting to:
- calculate h = the sum of the number of correct choices in the last 10 trials
(for the first round h = 5 since there are no previous choices, but after that h goes back to being sum of number of correct choices in the last 10 trials)
- calculate the trial score for choosing the correct answer for each trial 30 + 5*h
- calculate the trial score for choosing the incorrect answer for each trial 40 + 5*h
- store the trial score and the totalscore (totalscore = totalscore + trialscore)
To check if my code was working, used text to display the totalscore variable, however it only flashes 0 (the number I initialized the totalscore to at the beginning of the experiment).
I am not getting any error messages so I am not sure if there is a problem with my code, or if I put the codes in the wrong part of the custom code.
gainstotal = 0 gainstrial = 0 lastTen =  #initialize array to append to firstH = 5 h = 0
import numpy as np #for first trial they get 5 pts, after that it will be the number of correct answers in the last ten trials if trialN == 1: #for first trial, h = 5 if key_resp2.corr == 1: lastTen.append(firstH + 1) elif key_resp2.corr == 0: lastTen.append(firstH + 0) #keeping track of correct or incorrect trials else: if key_resp2.corr == 1: lastTen.append(1) elif key_resp2.corr == 0: lastTen.append(0) #calculate h (sum of last 10) if trialN < 11: h = np.sum(lastTen[ : ]) #if there are not 10 values in the array yet, add all the values else: h = np.sum(lastTen[-10: ]) #if there are more than 10, add the last 10 values
if key_resp2.corr == 1: gainstrial = 30 + 5*h else: gainstrial = 40 + 5*h
gainstotal = gainstotal + gainstrial
If anyone can help me I would really appreciate it!