When running the experiment from the builder in Pavlovia I get the following problem.
I define the following custom function using a code snippet at the beginning of the experiment. It just chooses a random number that I use later. doJitterLine is also defined at the beginning of the experiment.
However, when I try to run it in a code snippet at the end of another routine I get:
***ReferenceError: jitterLine is not defined**.
For now, I just copied the content of the function and pasted it in every routine I need to use it but which is not very optimal.
Is it possible to define a JS function at the beginning of the experiment to reuse it in later routines? If so, what I’m missing in my function definition?
@dvbridges, yeah that sounds very important
That function definition was created by the python to JS translator of the builder. Is that a normal thing that function definitions are translated but not assigned to a variable?
Yes, its just the way the translation happens, but you could also just assign your function to a variable in Python and use the new name. This should translate correctly without the need to adapt the JS, e.g., in Python
Thanks for this, has anyone managed to get this to work? For some reason, it isn’t working for me. i.e. defining function in python, resetting value in python, using function in python in an ‘auto->JS’ code component and then trying to get it to work online…