| Reference | Downloads | Github

Text of component being set before code that should run at "Begin Routine"

OS: MacOS 10.15.4
PsychoPy version: 3.2.4
Standard Standalone? (y/n): y

Hi, I don’t know if this is intentional but the text of the text component is being set before a piece of code that should run at the beginning of the routine. I’ve created a routine that has a code component that calculates the overall accuracy (placed at “begin routine”) and that updates a variable that should be displayed with a text component (with the “set every repeat” option), but it doesn’t work because, if I look at the compiled script, the setText function is being called before the code:

# ------Prepare to start Routine "thanks"-------
# update component parameters for each repeat
thanks_msg.setText(f'Score: {acc}%\n\nPunteggio: {acc} %\n\n\n\nThanks\n\nGrazie')
acc = str(int(np.array(corrects).mean()*100))

I’ve solved the problem by placing the code on a different routine that runs before the one that has the text component, but just wanted to let you know in case this is something that has to fixed for future releases.

Thanks for a great software.

You should also be able to fix it but placing the code component above the text component.