Function not found on-line – and when defined in ‘Before Experiment’ crashes Psychopy on upload

URL of experiment: Pavlovia

Hi folks.

I’m having some problems with using functions. I haven’t used these before in Psychopy so am wondering if they are reliable and ok – or what it is that I’m doing wrong. Have checked the crib sheets and forums etc…

Issue 1:

It would appear that if I define a function in ‘begin routine’ tab – it works fine locally, but then crashes when I try to run it online.


This functions as intended and prints ‘Hello World’ to runner. But when I upload this to Pavlovia and attempt to run it I get:

So searching around in the forums for this issue I come across this post: JS function not recognised

Where @wakecarter suggests putting your functions in the ‘Before Experiment’ tab. Ok. Let’s give that a go. But, unfortunately, now a different problem emerges.

Issue 2:

Whenever I try to Sync my experiment, Psychopy crashes out. Here’s the crash report I get:

Note, this particular crash is 100% reproducible by copying the same function definition into the ‘Before Experiment’ tab (see below). If I delete it here, Psychopy will sync just fine.

Any ideas or workarounds for this? I just wanna build a little function to clean up my code. :frowning:

Thanks folks,


I wonder if the issue is that your function doesn’t return anything. Try adding x = 1 to it and then return x

Hokay! So I gave that a go!

I put this code in the ‘Begin experiment’ tab, ran it, synced, then ran it online.

I also tried putting it in the ‘Before Experiment’ tab (pictured) and did the same. In both cases got the same results: It would now succesfully sync - but still crash online.

Screenshot 2024-01-16 at 12.30.51 am

Here’s the code where I called it from:

Interestingly that it did now not crash on trying to sync - BUT… the same error occured when I tried to run it online. :confused:

Here is the console output of chrome after the online crash:

Is this in any way meaningful?

In the meantime I have discovered some text about implementing functions in the ‘3 day intensive course notes’. So I assume that functions are expected to work as per usual in Python?

The function I want to write wouldn’t actually return anything either - it just set a whole bunch of images to opacity = 0.