| Reference | Downloads | Github

Begin routine from the builder doesn't work online

I am not sure whether it is a known issue but it seems that Begin routine from the code component in the builder isn’t recognize and thus doesn’t work online. It simply doesn’t define or modifie any variables or doesn’t do any other calculations.
Is it supposed to be this way?

I’m having an issue with my code component as well. Are code components in the Begin Routine tab just not being carried out at all? And have you noticed this issue with any other aspects of the code component?

I wonder if it could be temporarily remedied by moving the code to a different tab, such as “each frame”… I had to do this as a temporary remedy when giving the experiment on my local device and have yet to get my code components or loops to work on Pavlovia.

Here is a link to my issue as well, you can see if it is at all similar to your own.

Conditional Loop not working in Pavlovia

Hi @Yev
When you run the study online it converts all the python code to JavaScript code. It does this automatically for Builder components, but if you have any code components they have to be transalted to JS. Have you translated your python code components to JS yet?
If not, the easiest way to do it is to use the most recent version of PsychoPy, open your code component, select code type, and select Auto->JS. This will automatically translate your python code to JS, and this works perfectly most of the time.
Hope that helps.

Hi @Bobby_Thomas
The problem is not because of this. I don’t do it in python. I code directly in javascript and test the experiment online.

I am not sure it can be tricked. The code works perfectly in the start Experiment, and it works at the end routine.
I need program to randomly distribute values at the beginning of each trial. What I tried is:
make an additional routine and put the code at ‘end routine’ of that routine. So at least my values are randomly distributed before trial routine. But unfortunatelly it didn’t work.
I am not sure what else can be done about it. The solution to move the code to ‘each frame’ won’t work in my case.

Can we post it somewhere where some of the developers can comment on it?

Before doing so I would recommend posting your code here so that people can actually take a look at it. As is your question is very vague, and there is no way to tell if it might actually be a problem in PsychoPy or a problem with your code.

Connellyme, posted everything in his thread. There is nothing vague here.
Even the simplest code doesn’t work.
//begin Experiment
a = 12;
b = a;
This code will work as it is placed into begin Experiment.
If this code is placed into Begin Routine it will not work. It will simply be ignored there.

Ok, so it is the exact same project as Connellyme is building? If you are having the exact same issues then I would recommend moving this discussion to that thread.
Without any more details it is again going to be hard to tell if this issue is a PsychoPy problem or a problem specific to your experiment, and without any specific code examples about your project (unless they are the exact same as Connellyme) then it is going to be hard to give any advice on how to solve the problem.

I’m sorry for any miscommunication I caused!! I am working on a different project, but it appeared I was having a similar issue and wanted to share the progress that I had made or issues I had come across in hopes that it would help shed some light on a solution. That’s my bad, I’m sorry. I do have a separate thread for the issue as well (linked in my previous comment).

1 Like

No need to apologize, just trying to clarify and get more details from Yev. I think it is always nice to share other threads you might have going even if they don’t always give the perfect solution.


Has there been any progress on this issue? I am also having the same issue. If I create a new project, create one loop with one routine, and try to change the value of the variable in the ‘Begin Routine’ tab, the experiment wont run with the “NameError: name ‘my_variable’ is not defined”. If I define that variable in the ‘Begin Experiment’ tab, the experiment runs but ‘my_variable’ is never updated with a new value:

Begin Experiment:
my_variable = 0

Begin Routine:
my_variable = random()

I feel like I’ve successfully run code in the ‘Begin Routine’ tab awhile ago, is this a version issue? I am running Psychopy v2020.1.2

Thank you,


Have you defined random() to work online?

try to update your psychopy to 2020.1.3
At some point, in my case, it has started working.
I am not sure what I did. Partly, my problem was that I overlooked and copied a piece of my code to ‘beginning of experiment’ instead of ‘start routine’.
But at some point I switched to 1.3.2020 version and it worked.