OS (e.g. Win10): Win10 PsychoPy version (e.g. 1.84.x): 2021.1 Standard Standalone? (y/n) If not then what?: yes
**What are you trying to achieve?:
I built an experiment in the builder, which works fine. As soon as I switch to pavlovia, I get an error message: asarray not defined. I checked the compiled python code and found that two variable settings are executed with an asarray function:
**What did you try to make it work?:
So far, I checked whether my condition file provides values for these variables in all trials, but that looks fine so far.
Did anyone run into the same problem and could help me here?
Iâve had the same problem. I think itâs to do with the fact that asarray is defined in the Python version by importing numpy, but this does not happen when it converts to JS, so in JS asarray becomes âundefinedâ. Indeed, the cribsheet advises there will be problems converting from Psychopy to JS if numpy is imported.
Iâm trying to find a way to vary the duration of a stimulus without relying on âasarrayâ, or changing the JS version of the script so it doesnât rely on âasarrayâ but unfortunately I donât have a solution yet at the moment so would appreciate any help thanks
numpy.asarrary is a bit tricky, since it can perform a lot of different kinds of conversions. I would recommend writing a special solution for your cases.
this isnât numpy.asarray. As the question said, the js code just spontaneously started using asarray during translation. I had the same problem and I solved it by attaching a function called asarray that does absolutely nothing and returns the exact same input as the output at the beginning of the experiment.
it looks like.
asarray = function (something) {
return something;
}
This will be useful until the the psychopy team fixes this problem.
Thank you, good idea! Iâm just trying to implement it now, putting a code at the beginning of the experiment. However, it wonât translate to Pavlovia (specifically, when I try to sync, I get this error:
** Traceback (most recent call last):
File âC:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.pyâ, line 1339, in onPavloviaRun
self.fileExport(htmlPath=self._getHtmlPath(self.filename))
File âC:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.pyâ, line 759, in fileExport
target=âPsychoJSâ)
File âC:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.pyâ, line 73, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
File âC:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.pyâ, line 242, in compileScript
_makeTarget(thisExp, outfile, targetOutput)
File âC:\Program Files\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.pyâ, line 214, in makeTarget
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File âC:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.pyâ, line 242, in writeScript
entry.writeInitCodeJS(script)
File âC:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\routine.pyâ, line 140, in writeInitCodeJS
thisCompon.writeInitCodeJS(buff)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\experiment\components\code_init.py", line 221, in writeInitCodeJS
if len(str(self.params[âBegin JS Experimentâ])) and not self.params[âdisabledâ]:
TypeError: str returned non-string (type NoneType)
**
Unfortunately it doesnât solve the issue. Please see the screenshot below for my code piece. The unused ârccccâ variable was to check whether there was a general problem with Code_JS, but there wasnât, as it worked when I included this alone without adding the âasarrayâ function.
Verdi, Iâd like to pick up your problem as a little exercise into understanding parts of PsychoPy that are outside of my specialism. If thatâs OK with you, then could you share the repo? Here is a guide on how to do that: Searching for experiments on Pavlovia â PsychoPy v2021.1
Sure @thomas_pronk - Iâve just added you. Please let me know how you get on or if youâd like any more explanation. Currently, âitizâ is the name of the variable from a conditions file added into the âdurationâ section of the stimulus âblank_betweenâ (representing the ITI). This works fine locally. Alternatively, if I put a fixed value, e.g. 0.5, it works fine on Pavlovia.
The experiment is SequenceTask1 [PsychoPy]
Thanks a lot for offering to help
First of all, thanks for sharing your problems and solutions. Iâll defintely try to find a solution, but right now I donât have access to my account. I guess itâs probably due to the disruptions.(>>> authentication error: Unauthorised access to a GitLab API resource)
I managed to get the experiment to get to the introduction slide (followed by a tone). This is what I did: in the code-component code_JS, tab âBefore Experimentâ, I added the code below:
let asarray=function(something) {
return something;
}
No worries. I just want to implement a stimulus with variable duration. This can be done in Psychopy builder by putting a variable in the âdurationâ box, and then changing this variable in a conditions file or in code at the start of the routine. However it wonât transfer to Pavlovia because in the code of Psychopy it uses numpy, which doesnât transfer to JS