# Giving feedback adding points collected in every round

OS (MacOS Sierra 10.12):
PsychoPy version (1.84.2):

Hi!

I am new to Psychopy and I know nothing about coding. I have been trying to build an experiment and a lot of your answers helped me a lot so far, so thank you! However, I cannot find anything posts about counting the number of correct answers and turning them into points.

I am trying to replicate the Lockwood et al (2016) experiment about prosocial learning in which participants see two images and have to choose one in 3 seconds (pressing the âleftâ or ârightâ arrows). If they do not chose anything a âmissedâ message appears. If they choose an image, they get a fixation screen (for 2,0 s), then a message telling them if they won 0 (incorrect answer) or 100 points (correct answer) and then another fixation screen again (for 2,0, 2.5, 3,0, 3,5 or 4,0s). The conditions file has the images and the correct answer (the one that gives you 100 points) relate to each image. Here a picture of the flow of the loop.

At the end of the loop, after having shown the 16 images, I want a feedback screen telling the participants how many points they collected in the 16 rounds.

I have tried putting a code component in the trial1 routine as follows:
Begin experiment:
gainsThisRound=0
gainsTotal=0

Begin routine:
if resp.corr:
gainsThisRound=gainsThisRound+100
else:
gainsThisRound=0

End routine:
gainsTotal=gainsThisRound + gainsTotal

Then in the gains1 routine I put a text with \$gainsTotal

If I do this, the text showing after the 16 rounds is always 0. I am quite lost here, I donât know anything about coding so I donât even know if what I wrote makes sense.
I also thought about the possibility of counting the number of correct responses and multiplying them by 100 to get the total points so I made another version where instead of the code mentioned above I put a piece of code as follows:
Code for trial1 routine:
Begin experiment:
gains = 0

Begin routine:
if practice.thisN == 0:
number_correct = 0

End routine:
if resp.corr:
number_correct = number_correct + 1
else:
number_correct = number_correct

Code for gains1 routine:
End routine:
gains = number_correct *100 #every correct answer gives you 100 points

In this routine (gains1) I put a text with \$gains

But again, I only get a 0 as the count of total points.

Could you guys help me out?

Thanks!
Lara

It helps us immensely if you surround your code with triple backticks ``` before and after so it gets properly formatted (particularly so we can see the indenting).

But it looks like you are on the right track with the first set of code. Just try shifting the code in your `Begin routine` tab to also be in the `End routine` tab. You canât check whether the response was correct at the beginning of the routine, as the person hasnât yet had a chance to make a response at that stage. Hence your count will always stay at 0.

Hi Michael! Thanks for you answer.
Here is the code, I didât know how to format it, thanks.

Code in the trial1 routine:
Begin experiment:

``````gainsThisRound=0
gainsTotal=0
``````

Begin routine:

``````if resp.corr:
gainsThisRound=gainsThisRound+100
else:
gainsThisRound=0
``````

End routine:

``````gainsTotal=gainsThisRound + gainsTotal
``````

Then in the gains1 routine I put a text with \$gainsTotal

The other thing I tried:
Code for trial1 routine:
Begin experiment:

``````gains=0
``````

Begin routine:

``````if practice.thisN==0
number_correct = 0
``````

End routine:

``````if resp.corr:
number_correct = number_correct + 1
else:
number_correct = number_correct
``````

Code for gains1 routine:
End routine:

``````gains = number_correct *100 #every correct answer gives you 100 points
``````

In this routine (gains1) I put a text with \$gains

I tried doing what you suggested, putting the code also at the End of routine but it still shows only 0 as a feedback.

1 Like

Is the text in the your text component set to update every routine?

1 Like

It wasnât, now it is, and it works!! Thank you very much Michael!

We are making some changes for our experiment. There are now two conditions: playing for one self and playing for an NGO, and we want to show the total points separately for one self and for other, so I added a column in the variables file and adapted the code to this:
Begin of routine:

``````gainsThisRound_self = 0
gainsThisRound_other = 0
gainsTotal_self = 0
gainsTotal_other = 0
``````

End of routine:

``````if resp.corr and S_O == "1":
gainsThisRound_self = gainsThisRound_self + 100
elif resp.corr and S_O == "2":
gainsThisRound_other = gainsThisRound_other + 100
else:
gainsThisRound_self = 0
gainsThisRound_other = 0

gainsTotal_self = gainsThisRound_self + gainsTotal_self
gainsTotal_other = gainsThisRound_other + gainsTotal_other
``````

The S_O is the name of the variable in the excel file. Coded with 1 is when playing for yourself and coded with 2 is when playing for an NGO.

At the end of the experiment we are showing a text with

``````\$gainsTotal_self
``````

and

``````\$gainsTotal_other
``````

I already put the text to set every repeat, but still it only shows 0 points.
When I look at the data file, Psychopy is not saving the collected points.

I would be very grateful if someone could tell me, what I am doing wrong and what should I change to make it work.

You can run the experiment to understand better what I mean.

Thank you very much in advance!!
Lara

trialTypes_prueba.xlsx (10.1 KB)
ProsocialLearningpruebas.psyexp (57.2 KB)

I suspect PsychoPy is interpreting your `S_O` variable as an integer rather than a character string (as it generally should). So try amending your checks like this:

``````if resp.corr and S_O == 1: # check against an integer rather than a string
``````

Do you mean that no variable with that name is added to the data file, or that it only contains zeros?

Hi Michael!

Thans for your answer. I changed the name of the variable to SELOT, to avoid confusions. It works the same as it did before: it works but the end result is always zero. I think that the problem is that it is not saving the points. There is a column in the data file, but it only contains zeros T_T

But more saliently, did you remove the quotes around the `1` and the `0`? The actual name of the variable isnât really an issue.

No, PsychoPy is saving the data it has, itâs just that the values are all zero. This indicates that the problem is somewhere in the logic of the code which should be providing non-zero values as required. Youâll need to debug that. One way is to print out what steps get reached in the code, e.g. modify it as below:

``````if resp.corr:
print('Response is correct.')
if S_O == 1:
print('S_O is 1')
gainsThisRound_self = gainsThisRound_self + 100
elif S_O == 2:
print('S_O is 2')
gainsThisRound_other = gainsThisRound_other + 100
else:
print('S_O check is invalid')
else:
print('Response is incorrect.')
gainsThisRound_self = 0
gainsThisRound_other = 0

print(gainsThisRound_self)
print(gainsThisRound_other)

# continue to totals and saving data
``````

Also note that you are resetting your totals to zero at the start of each routine: I donât imagine that is intended, as it means the total will never exceed the score from a single routine.

Hi Michael, thanks again for your answer. As I said, I donât know anything about coding, so I didnât understand what you meant by [quote=âMichael, post:7, topic:2200â]
your S_O variable as an integer rather than a character string.
[/quote] I thought the problem was with the variable name. -_-U
I did what you suggested, and removed the quotes around 1 and 0 and now it saves something different than zero, but it is not adding 100 points every time an answer is right, but 200 or 300 points, I donât know why. Do you know what the problem there might be?

I tried to debug it, but then Psychopy is not working anymore. When I click on the run button, it doesnât do anything (meaning the is no reaction from the program, literally nothing happens, it is as if I hadnât clicked on the run button).

Thanks again!