Error message: asarray not defined

Thank you so much! I don’t quite understand how this can be used to add a variable duration for a stimulus in Pavlovia?

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.

3 Likes

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)
**

Do you know why this might be?

Thank you so much :slight_smile:

Hey @verdi,

Could you share your gitlab with me (tpronk), then I’ll have a look.

Best, Thomas

@verdi

In code_JS this should be written as

asarray=function(something) {
return something;
}

Please let me know if this solves the issue.

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.

Thanks for taking the time to look at this :slight_smile:

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 :slight_smile:

My pleasure! I’ll wait a little while to collect some more experiments that need assistance, and then I’ll dive into it

I’ll need developer access (you made me guest)

Hi everyone,

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)

Best,

Kathrin

1 Like

I think I’ve just given you developer access. Let me know if any problems :slight_smile:

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;
}
1 Like

Thanks so much! Did you manage to set one of the stimuli to a variable duration?

Haven’t tried. Can you give me some more pointers on how you’d like to have that?

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 :frowning:

Aha, is that the asarray issue? If so, tried the fix above? If not, your experiment was named “sequence [something]” right?

I had this error, and your workaround worked for me, Thomas!

1 Like

Hi thomas,

Now that Pavlovia is working I could test your solution. It works perfectly. Thanks a lot for your support.

Best,

Kathrin

1 Like

Hi,

I have the same issue with the asarray error, because it automatically appears in my JS code when I implement a stimulus duration. I tried to use the solutions above, but they did not help. Do you have any idea why this error keeps happening?
Thanks a lot!