Displaying the final score

I created and experiment where the participant hears a sentence and has to click on the exact sentence heard by the participant which is displayed on the screen.
i have added code to display if the responses are correct or incorrect.but what I need is,I want to display the total score after a specific block.
following is the code provided to display the total score.somehow after the last stimuli the result is displayed and it is stuck there.
total score is not displayed.
please help

the following is the code provided on the "


experiment sentences 4 choice - Copy (2).psyexp (30.1 KB)
begin routine" window under code for β€œtotal score” routine

from psychopy import visual, core, event

Set up the window

win = visual.Window(size=(800, 600), fullscr=False)

Create a text stimulus for displaying the score

score_text = visual.TextStim(win, text=β€˜Score: 0’, pos=(0, 0))

Initialize the score

score = 0

Main experiment loop

while True:
# Run your experiment code here

# Assume key_resp_corr is defined and holds the correctness of the response

if key_resp.corr == 1:
    score += 1
else:
    score += 0

# Update the text stimulus with the new score
score_text.text = f'Score: {score}'

# Draw the score text on the window
score_text.draw()
win.flip()

# Wait for a key press to proceed to the next trial
keys = event.getKeys()
if 'escape' in keys:
    break

Close the window at the end of the experiment

win.close()
core.quit()

code ended.

i created a routine score_text and corresponding to text I have typed {score} to display the correct score.

Hello

you have to count the total score in feedbackout, not total_score.

Why you do include

from psychopy import visual, core, event

# Set up the window
win = visual.Window(size=(800, 600), fullscr=False)

# Create a text stimulus for displaying the score
score_text = visual.TextStim(win, text='Score: 0', pos=(0, 0))

# Initialize the score
score = 0

# Main experiment loop
while True:
    # Run your experiment code here
    
    # Assume key_resp_corr is defined and holds the correctness of the response
    
    if key_resp.corr == 1:
        score += 1
    else:
        score += 0

    # Update the text stimulus with the new score
    score_text.text = f'Score: {score}'
    
    # Draw the score text on the window
    score_text.draw()
    win.flip()
    
    # Wait for a key press to proceed to the next trial
    keys = event.getKeys()
    if 'escape' in keys:
        break

# Close the window at the end of the experiment
win.close()
core.quit()

The Builder will write this code for you. You only need to write the code to calculate the total score and assign it to a variable.

if key_resp.corr == 1:
    score += 1

See here for information about feedback-messages Builder - providing feedback β€” PsychoPy v2023.1.2

Best wishes Jens

1 Like

if key_resp.corr:
msg = β€˜βˆšβ€™
else:
msg = β€˜Γ—β€™

this code is written in feedback rout.

to code to calculate the total score should I add it as a continuation here?

Also how do I display it?

Hello

use the code-component in the routine feedbackrout and change the code from

if key_resp.corr:
    msg = '√'
else:
    msg = 'Γ—'

to

if key_resp.corr:
    msg = '√'
    score += 1
else:
    msg = 'Γ—'

Initialize score in the Begin Experiment tab.

score = 0

Delete the code in the code-component code_3 in the routine total_score.

Insert the following in the code-component code_3 in the Begin Routine tab.

msgTotalScore = str(score)

Refer to msgTotalScore in your text-component score_text.

grafik

Best wishes Jens

1 Like

Thank you so much for your help.Its working perfect.

Also, I would like to know if it is possible to add the following procedure to the current experiment.

I present 10 stimuli in a set and if the score is below 8 the experiment has to move to next set of 10 stimuli automatically. Can I add all the 10 sets of stimuli in a single excel sheet by leaving one row empty after each set? Is that how I should give the stimuli in conditions file? And if this is possible how can I do this
Please help!
Thank you

Hello Gowri,

it is better to post new topic than to extend one with a solution.

Best wishes Jens

1 Like