In my experiment participarts are asked to respond with the up and down keyboard arrows to the images they see on the screen. But points to gain or lose vary between 1-5 for each trial. For example, on the 1st trial If the participant responds correctly will get 5 points but if the participant responds incorrectly will lose 3 points. On the other hand, on the 8th trial If the participant responds correctly will get 3 points but if the participant responds incorrectly will lose 1 point. You can see it on my condition file.
I need the total score to be cumulative where the correct response adds the points (between 1-5) and also an incorrect response subtracts the points (between 1-5) from.
# Add correct and incorrect points in each trial
correct_points = correct_points + CorrPoint
incorrect_points= incorrect_points + IncorrPoint
# get the cumulative point
cumulative_points= correct_points - incorrect_points
#And save the data
thisExp.addData ("cumulative_points", cumulative_points)
Change names based on the component names that you defined.
Thank you very much @Omidrezaa your reply was very inspiring.
At first it worked partially. It just added up correct points but it didn’t see the incorrect points that’s why it didn’t subtract them from cumulative scores. Then I made some changes with the help of a friend. It works perfectly well now. I leave the code below for anyone who needs.
In the Begin Experiment Tab:
#define variable
cumulative_points = 0
In the End RoutineTab:
if keyboardx.corr:
cumulative_points = cumulative_points + CorrPoint
elif not keyboardx.corr:
cumulative_points = cumulative_points - IncorrPoint
#And save the data
thisExp.addData (“cumulative_points”, cumulative_points)