psychopy.org | Reference | Downloads | Github

Points counter/ score board based on correct responses, where different responses to different stimuli are worth different points


#1

Hi, I am new to using PsychoPy in general, and also coding. I am trying to find a way to have a score board on my screen at all times (which works fine with the text file), but I can’t get it to add the points based on the different responses.
Basically, arrows show up on the screen, and the participant has to respond with the keyboard arrow of the opposite direction to the arrow presented. There are different color arrows (i.e., red, blue, and green), where the correct response for each arrow type is worth a different amount of points (i.e., 1, 5, and 10, respectively).
I added a code file to the builder view (since I am not familiar enough with coding to do my whole experiment through python), but I honestly have no idea how to set it all up, and I have tried looking up other discussions here.
So essentially, I need the score to be cumulative, where the correct response adds the points, and an incorrect response subtracts the points from the total score (e.g., incorrect response on a green arrow is worth -10 points).
I would really appreciate any help.
Thank you


#2

Hi @Angiemareidion, you can make this work with the keyboard component set up to receive the correct response from your conditions file. So, have a column called “corrAns” or something similar, and put the correct response for each trial in that column. Add the $corrAns variable to the relevant param in the keyboard component. Put another column in the conditions file with the color of the arrow for that trial, called “arrowColor”. Now PsychoPy will know the correct response and color of the arrow on every trial. You will need a text component to display your score, call it “score”, set it to update on every repeat with $mainScore in the textbox, and position it wherever you want to position it with no duration. Add a code component, and use the following code in the relevant tabs:

# Start experiment
arrowVal = {'red': 1, 'blue': 5, 'green': 10}
mainScore = 0

# End routine
if keyboard.corr:  # if the response was correct
    mainScore += arrowVal[arrowColor]
elif not keyboard.corr:  # if the response was incorrect
    mainScore -= arrowVal[arrowColor]

# The text component will update automatically because of set repeat setting

#3

Hi, this was very useful. Due to the naming I did in my excel file, I changed the names so they correspond but all in all its working well, except that it won’t deduce the points for incorrect responses during the trials, although this is the code I have for #End routine:
if CorrAns: # if the response was correct
mainScore += arrowVal[Colour]
elif not CorrAns: # if the response was incorrect
mainScore -= arrowVal[Colour]

#mainScore += 1
print(Colour)
print(mainScore)

It just adds on the points whether the answer is correct or not, even if no response is made (it just seems to assume everything is a correct answer, although I have set CorrAns to be specifically left or right depending on the stimulus in my excel sheet.
Any recommendations??
Thank you!


#4

Also, is there a way to set a lack of response as an incorrect response?
Thanks
Angie


#5

Oh, I think the error is because you are using the variable corrAns in the conditional. You need to use the keyboard attribute keyboard.corr like in my example, where keyboard is the name of your keyboard component.

Also, in the code I have given, lack of response will also count as an incorrect response.