Block feedback as image issue

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v.2022.1.1
Standard Standalone? (y/n) If not then what?: n?
What are you trying to achieve?: I’m building an experiment where participants categorise stimuli as either radial(r) or concentric(c), and in this script they are to receive feedback after a run of 108 trials (block feedback). This feedback is an image of a bar that is filled in dependent on what percentage correct they got. I have 8 separate images correlating to varying degrees of %accuracy. With the help of a fellow PhD student, we managed to make the feedback image correctly correspond to the participant’s %correct on the practice stage of the experiment. There are 4 runs after the practice run - the first does not have feedback as it will be used to assess baseline performance. The next 3 runs should have feedback.

What did you try to make it work?: To make it work for the practice run, I added custom code:

*Begin Experiment

feedback_image = 'bar_50-60_2.png' 

*Begin Routine

perCorr_practice = Practice_trials.data['key_resp_practice.corr'].mean() * 100

# if statements corresponding to %correct and block feedback images

if  perCorr_practice <= 20:
    feedback_image = 'bar_50-60_2.png'
    
elif 21 <= perCorr_practice <= 30:
    feedback_image = 'bar_60-65_2.png'
    
elif 31 <= perCorr_practice <= 40:
    feedback_image = 'bar_65-70_2.png'

elif 41 <= perCorr_practice <= 50:
    feedback_image = 'bar_70-75_2.png'

elif 51 <= perCorr_practice <= 60:
    feedback_image = 'bar_75-80_2.png'

elif 61 <= perCorr_practice <= 75:
    feedback_image = 'bar_80-85_2.png'

elif 76 <= perCorr_practice <= 90:
    feedback_image = 'bar_85-90_2.png'

elif 91 <= perCorr_practice <= 100:
    feedback_image = 'bar_90-100_2.png'

image_Blockfeedback = visual.ImageStim(
win=win,
name='image_Blockfeedback',
image=feedback_image, mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.5, 0.5),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)

I then copied these codes and added them to my Run2, Run3 & Run4 feedback routines. I adjusted them for each run loop i.e:

perCorr_run2 = trials_Run2.data['key_resp_Run2.corr'].mean() * 100

# if statements corresponding to %correct and block feedback images

if  perCorr_run2 <= 20:
    feedback_image = 'bar_50-60_2.png'
    
elif 21 <= perCorr_run2 <= 30:
    feedback_image = 'bar_60-65_2.png'
    
elif 31 <= perCorr_run2 <= 40:
    feedback_image = 'bar_65-70_2.png'

elif 41 <= perCorr_run2 <= 50:
    feedback_image = 'bar_70-75_2.png'

elif 51 <= perCorr_run2 <= 60:
    feedback_image = 'bar_75-80_2.png'

elif 61 <= perCorr_run2 <= 75:
    feedback_image = 'bar_80-85_2.png'

elif 76 <= perCorr_run2 <= 90:
    feedback_image = 'bar_85-90_2.png'

elif 91 <= perCorr_run2 <= 100:
    feedback_image = 'bar_90-100_2.png'

image_Blockfeedback = visual.ImageStim(
win=win,
name='image_Blockfeedback',
image=feedback_image, mask=None, anchor='center',
ori=0.0, pos=(0, 0), size=(0.5, 0.5),
color=[1,1,1], colorSpace='rgb', opacity=None,
flipHoriz=False, flipVert=False,
texRes=128.0, interpolate=True, depth=-1.0)

What specifically went wrong when you tried that?:
I do not get an error message when running the experiment. Instead, the feedback image for Run2, Run3 & Run4 only displays the default image that I initialised feedback_image to (‘bar_50-60_2.png’), instead of changing the image based on the %correct as it does in the practice run.

The experiment code is quite long so I am not sure if it is ideal to post it all here - but please let me know if you need to see it all. If you need to see it, also let me know the correct way to show it on here (I’m a newbie when it comes to both coding and experiment generating).

Thank you for your time and help in advance.
Ethan

I think that this issue may be your A < X < B construction, which is unnecessary due to the use of elif statements. Try

perCorr_run2 = trials_Run2.data['key_resp_Run2.corr'].mean() * 100

print('perCorr_run2',perCorr_run2_ # To check value in runner for debugging

# if statements corresponding to %correct and block feedback images

if  perCorr_run2 <= 20:
    feedback_image = 'bar_50-60_2.png'
  
elif perCorr_run2 <= 30:
    feedback_image = 'bar_60-65_2.png'
    
elif perCorr_run2 <= 40:
    feedback_image = 'bar_65-70_2.png'

elif perCorr_run2 <= 50:
    feedback_image = 'bar_70-75_2.png'

elif perCorr_run2 <= 60:
    feedback_image = 'bar_75-80_2.png'

elif perCorr_run2 <= 75:
    feedback_image = 'bar_80-85_2.png'

elif perCorr_run2 <= 90:
    feedback_image = 'bar_85-90_2.png'

elif perCorr_run2 <= 100:
    feedback_image = 'bar_90-100_2.png'


Secondly, it is good practice to create image components at the start of the experiment and then customise them during its course. If you did this then you would only need

image_Blockfeedback.setImage(feedback_image)

and then (if image_Blockfeedback image was created in code or is a component in a different routine)

image_Blockfeedback.setAutoDraw(True)

Also, if possible, it is good practice to reuse routines rather than create almost identical copies.

1 Like

Hi wakecarter,

Thank you very much for your response. I did the things you said and it seems to work fine now. I was a tad confused about where to add the code

image_Blockfeedback.setAutoDraw(True)

and when I put it where I thought I should, it ended up just displaying a feedback image over the top of my other routines without disappearing. I chopped and changed it around and eventually got it to work.

Also thank you for your good practice advice, as I’m new to all this and good practice is always something to strive for.