psychopy.org | Reference | Downloads | Github

Providing appropriate feedback on first trial

Hi all,

I’ve been trying to provide feedback to participants after they select one of two pictures on every trial, using the following code from Builder - providing feedback:

# Initialize components for Routine "feedback"
msg=' ' #if this comes up we forgot to update the msg!
text = visual.TextStim(win=win, name='text', text=msg)

# -------Start Routine "feedback"-------       
if not key_resp.keys :
     msg="Failed to respond"
elif key_resp.corr: #stored on last run routine
     msg="Correct!"
else:
     msg="Oops! That was wrong"

Not surprisingly, my code fails to update the content of msg during the first trial, so I always get an empty ' ' message as feedback after the first response. I was wondering whether there’s any solution to this problem, i.e. a way of initializing the components of the feedback route without having to define msg right away?
Thanks!

Have you enabled ‘Store correct’ along with a correct response for you key_resp component? Does the response for the trials following the first one behave correctly?

This is all a matter of the order of operations. The msg variable just needs to be updated before it is provided to the text stimulus. It’s not clear to me if you are using Builder or directly editing scripts. But if you are using Builder in the intended way (using code components) to insert your custom code, then the order of operations is taken care of for you.

i.e. you just need to insert the code component above the text stimulus in the timeline pane. That way, the msg variable is updated before the text stimulus gets to refer to it. The text stimulus does need to be set to update on every repeat, of course. In that case, you don’t need to provide dummy initial content for msg. Builder is cover enough to know that the content will be changing on every repeat, so it just provide its own dummy content when the text stimulus is initialised at the start of the experiment.

1 Like