Conditional cross or tick to be displayed with conditional text component following response

Hi, I am building a word and object association task and I would like to show a tick or a cross after the participant has given their answer. I would like the tick or cross to be presented on the same routine(display) as the feedback(which shows how much money they have won following a correct answer and an ongoing total score). The total score display is a code component that I have added onto the feedback routine in coder following initial construction in the builder.

I have read some previous suggestions like making two routines, (right, wrong) and creating a loop to skip a routine depending on response, but then this will not be displayed on the same display as the total score (I’m assuming), therefore I am unsure how to do this.

Currently, I have added the two image components (ticks and cross) into the feedback routine and they both show up at the same time as the feedback which is expected with the way its coded, but now I want to set up a condition/loop for the tick and cross to only show up given the correct response.

Where have you seen this? I’m guessing there must be a niche use case for it.

I usually have one image set to update each repeat which can take a tick or a cross and then set the correct image file in end routine of the trial. Alternatively you could set start conditions for your tick and cross images, but in that case you’ll need to use Routine Settings to give the feedback routine a duration unless if ends on a key/mouse press already.

So just have one image component (image_10) in the feedback routine and then in the end routine write something like this?

if key_resp_3.corr==1:
      image_10.setImage (file directory of tick image)
elif key_resp_3.corr==1 and key_resp_5.corr=1:
     image_10.setImage (file directory of tick image)
elif key_resp_3.corr==1 and key_resp_5.corr=0:
    image_10.setImage (file directory of crossimage)

… for example,

would it work for multiple conditions of correct/wrong responses?

Even simpler than that:

feedbackImage = 'cross.png'
if key_resp_3.corr==1 and key_resp_5.corr=1:
     feedbackImage = 'tick.png'

Then set image_10 to display $feedbackImage

Yes it would work for multiple conditions.

Have you seen the loop method you mentioned on this forum?

I think I saw it in relation to a delayed match to sample task, and thought it could be a way to do it.

I did a similar loop in my task, such that if they get the first part wrong, it skips two routines and goes straight to the feedback. I did this in the coder view which meant I had to indent all the lines of code in the two routines it needed to skip and then end the loop before the feedback routine began. It worked but it took a long time.

I tried the code and I am getting AttributeError: ‘str’ object has no attribute ‘status’
on the first line of the code below


            **if image_wrong.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:**
                    # keep track of start time/frame for later
                    image_wrong.frameNStart = frameN  # exact frame index
                    image_wrong.tStart = t  # local t and not account for scr refresh
                    image_wrong.tStartRefresh = tThisFlipGlobal  # on global time
                    win.timeOnFlip(image_wrong, 'tStartRefresh')  # time at next scr refresh
                    # add timestamp to datafile

the name image_wrong is image_10 component in my code

Search for image_wrong in your experiment. It looks like it’s an image component but is also being set to something else.

yes i think it was being assigned twice. I have removed it but now the conditions I’ve set do not seem to match the correct response. Also the first response on every trial comes up with a default image png.

if key_resp_3.corr==1 and key_resp_5.corr ==1:
            feedbackImage= 'right.png'
elif key_resp_3.corr == 1 and key_resp_3.keys == "left":
            feedbackImage='right.png'
elif  key_resp_3.corr==1 and key_resp_5.corr ==0:
            feedbackImage= 'wrong.jpg'
elif key_resp_3.corr == 0:
            feedbackImage= 'wrong.jpg'
image_wrong.setImage(feedbackImage)

sometimes when the key_resp_3 is correct and is left it comes up with a cross rather than a tick. Not sure why.

Where is this code in relation to your feedback routine? It sounds like it’s in Begin Routine in the feedback routine itself below image_wrong.

If elif key_resp_3.corr == 1 and key_resp_3.keys == "left": is failing you could try elif key_resp_3.corr == 1 and "left" in key_resp_3.keys:

It’s in the end routine as you suggested earlier.

I tried the change and it still doesn’t work, the other conditions seem to not work either. I’m not sure if its reading the code properly.

To check the code add:

print('key_resp_3.corr',key_resp_3.corr)
print('key_resp_5.corr',key_resp_5.corr)
print('key_resp_3.keys',key_resp_3.keys)
print('feedbackImage',feedbackImage)

at the bottom and look at the output in the runner

the code prints the correct image but displays the opposite one.

key_resp_3.corr 1
key_resp_5.corr 0
key_resp_3.keys left
feedbackImage right.png

this showed a cross instead of a tick

Of the trial routine or the feedback routine?

of the feedback routine – if I add it to the trail routine is that in the previous routine?

If you run code at the end of the feedback routine then that is too late to affect that feedback. It needs to be at the end of the trial routine or the beginning of the feedback routine.

I am assuming that you have a trial routine followed by a feedback routine.

I moved it to the begin routine and it works now! I was wondering why it needed to be at the end routine but I think I just misread what you wrote! Thank you for your help!