How to set the correct rate to pass 80% in the practice stage

Computer system: os12.6

Psychopy version: v2021.2.3

Interface: Builder

The problem encountered: I want to set the correct rate of 80% in the practice stage to enter the formal experiment, otherwise return to practice again.Encountered difficulties when adding code, it is not clear where to insert the code and the correct code instruction.

The setup I’ve made: The practice phase has a loop called exone_pracloop that randomly selects 10 trials out of 32 stimuli and presents them with true and false feedback (these above work fine).
(Please see attached:one.png)

The part that can’t be realized yet is:
judge the correct rate of 10 trials, if the correct rate reaches 80%, present the passed pictures in “infor” (pictures have been prepared), and then enter the formal experiment; the correct rate does not reach 80% , then re-read the instructions and practice again.

Below is my code:
I inserted a code component called exone_prac_Msg in exone_prac_feedback in exone_pracloop loop
(Please see attached:two.png)

my question:
I want to judge the correct rate in the practice stage, and present the pictures of passing or failing according to the correct rate, and determine to enter the formal experiment or re-read the instruction. Where should I insert the code components and what syntax should I insert in the code components.

Hello

you might to look here

or search the forum for similar solutions.

Best wishes Jens

Thank you very much for your reply!

Combined with your reply, I tried to modify my code,Eventually I adjusted the location of the code and run the experiment successfully. After trying my best to fail many times, I found that putting the code for assigning values ​​to the image component and the image component in a same routine will crash during operation because they are running at the same time.

The assignment code needs to be before the picture is rendered, so I put it in the end routine part of the inner loop code in the practice phase.Put the picture component in the last part of the outer loop of the practice phase.

Thank you very much for your help when I encounter difficulties!
Best wishes :heart:

The specific code and operation are as follows:
Add the following code to the loop code in the innerloop of practice(exone_prac_feedback)

Begin routine

score = []
scorr = ()

End routine

score.append(key_resp_prac.corr)
if average(score) >= 0.8:
  imageVariable = 'exone_pracsuccess.tiff'
else:
   imageVariable = 'exone_pracfail.tiff'

Add a picture control in the outer loop of the exercise phase(practice_back_image), the picture uses
$imageVariable
Then add a code to end the loop at the end of the outer loop(prac_feedback)

End routine

if average(score) >= 0.8:
   exone_prac_back_loop.finished = True