Change storing variable name over loops

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): v2022.2.2
**Standard Standalone? (y/n): Yes

I have a loop which runs 3 times over a list of 4 excel spreadsheets (12 different files nested in 3 files corresponding to the runs) in a counterbalance experiment. At the end of the trial the answer is stored and a trigger is sent. My problem is that I store the answer in a variable and set it with value 0 at the beginning of the experiment in order to provide feedback and at the end of the routine, this variable increases by 1. So in run 1 the feedback is correct, but in the second and third are wrong. I assume that is because the variable that stores the answer is not set in 0 again. I would like to create 3 different variables depending on the run (1, 2 or 3) without creating a new routine.

begin experiment tab:

var_store_correct = 0
var_store_total = 0

end routine tab
#check for correct answer
if m_vo_t1.leftButton==corrAns:
    port.write(tCorr) 
    answer = 1
    var_store_correct+= 1
else:
    port.write(tInc)
    answer = 0
    var_store_correct += 0

#append the value of correct or incorrect
thisExp.addData('ans_vo1', answer)

#update variable for trials and correct responses
var_store_total += 1 # this is called in a feedback routine



```

At the end I would like to have var_store_total_0, var_store_total_1, var_store_total,2, var_store_correct_0, var_store_correct_1, var_store_correct_0 and, ans_vo1_0, ans_vo1_1, ans_vo1_2

Hi,

I am not sure I fully I understand what you are after but the var_store_correct += 0 adds 0 to the existing value. So, if in trial 1 the answer was correct, then the var_store_correct will be 1, if in trial 2 the answer is incorrect, then at the end of the routine of trial 2 the var_store_correct will still be 1 as it adds 0 to the existing value of the variable.

Perhaps this is what you want but if not then the correct way to write this would be var_store_correct = 0

Best wishes
Yiannis

Thank you Yiannis for your reply!

I use var_store_correct and var_store_total in the feedback routine to calculate % of correct answers. But, as I run this 3 times, every feedback is based on this unique variable instead of get 3 different %

You could make your unique variables lists and address the entry corresponding to the loop number, eg correct[trials.thisN]