| Reference | Downloads | Github

Unable to convert: udefined to a number when running the study online (Pavlovia)

URL of experiment:

PsychoPy version is 3.0.6, and Mac OS 10.14.4.
I used Google chrome73.0.3683.103

Description of the problem:
I tried to move a rectangle from left to right in a web browser.
My sample program was very simple; I set a polygon component and changed the shape to “rectangle” and the position to (t, 0) and “set every frame”.
This program ran successfully in my computer, but it did not run online.

I saw an error message as follows:

Unfortunately we encountered an error:

when converting an object to its numerical form
unable to convert: undefined to a number.

Try to run the experiment again. If the error persists, contact the experimenter.

Is it possible to move a rectangle online?

1 Like

Hi @kurokida, I think this issue relates to an existing problem that has been fixed, but will not be released until PsychoPy 3.1.0, which is imminent i.e., within a day or so. The problem occurs because the position variable t is not defined until the trial begins. So, when the rect stim is initialised with the position ‘t’ variables, it cannot be found.

If you are unable to wait for the next release, a quick fix would be to manually set the position variables using a code component at the beginning of each routine. You would first need to create your rects with default positions e.g., [0,0]. Then, in a code component:

polygon.setPos([t, 0]);
1 Like

Thank you for your kind reply. I would wait for the future release.

Thanks @dvbridges for the above, this is helpful!
I have encountered a similar problem when I tried to run one of my experiments online. The experiment was designed in version 3.0.4.
I have now upgraded to the new realise 3.1.0 but I am not sure what I need to do for the changes to take place to avoid further errors.

I tried one thing - I ran the experiment in the new version of PsychoPy and it works fine. I re-uploaded the index.html on GitLab but the error persists.

The error concerns the position of an image which changes on every trial depending on the condition. The position is specified in an excel file. In the image component I used the function eval to facilitate the conversion to numerical form:

Here is the error that shows up on Pavlovia

Any advice will be hugely appreciated!

Hi @MartaT, rather than using eval, you could have separate columns for your x and y position values in your conditions file, and then use these variables in your position param. E.g., [posX, posY].

Thanks @dvbridges, I tried this but the error persists, exactly the same as above.
I tried to set the position at the start of the routine using a code component as suggested in your first response but it did not make a difference.

Everything works fine in PsychoPy.

Would you mind sharing your conditions file?

There are two files for different types of blocks.
conditions1.csv (1.5 KB)

conditions2.csv (1.5 KB)

Well that seems ok. Could you please share the URL to your task so I can see the error?

Here is the link:

I just noticed that apart from the main error there is still a message to inform that I should upgrade to the newest version of PsychoPy because the old JS library is being used. That’s after I just exported the experiment again straight from PsychoPy version 3.1.0.

If you have 3.1.0, set the version to blank or latest, export html and resync with Pavlovia. Currently, the PsychoJS version you are using is b11, a beta version - this is why you are receiving the msg about upgrading at the beginning of your task. I think this problem should go away if you are using 3.1.0. Just to check, have you used a string for your positions? Currently, they read ['posX', 'posY']
instead of [posX, posY]. This will also cause an error, if you are using a string representation of your variables.

1 Like

So the version was set to blank originally, I just changed it to “latest”, exported and synced and the problem of the position is solved! I am not sure why the positions appeared as strings, in the builder I specified [posX, posY] - without the inverted commas.

However, there is a new problem. Now that the position is solved, there is a similar error with jitter. The jitter is undefined:


In the builder, the jitter is defined in the code component, begin routine:
jitter = random() * (1.0 - 0.5) + 0.5 # set the time 0.5 to 1 s
jitter = round(jitter, 1) # round to 1 decimal place

I tried one thing - I created an empty variable for jitter in the begin experiment tab
jitter = [] but it didn’t help because the error seems to be related to the routine specifically as it only appears after the instructions.

Ah, so if you have some Python code, you will need to translate this into JavaScript manually. In the code component, select a code type of “Both”, so that JavaScript appears side by side with the Python.

You get the error, probably because jitter is not part of the JS code. See this link for generating random numbers in JS. If you have any problems, just post them here.

Hi @dvbridges thanks for explaining the above!

I have now tried to translate the code. I consulted it with my colleagues and the code itself seems to be ok. I think. At least there are no unidentified objects.

The jitter is first applied to the fixation cross - this is the first thing that appears on the screen when starting the task. But there seems to be an issue that once the fixation cross shows up, it does not disappear. It basically blocks the experiment. I think that this is related to the “jitter” object because when I tried to specify the number of milliseconds for the duration of the fixation cross it did disappear. I am not quite sure why the jitter is not being applied.
In the fixation cross window it looks like this:

Thanks for your help!

Hi @MartaT, I think the problem is with the use of var to define the jitter variable in your code component. PsychoPy will do this for you, which gives your variables global scope, so that can be used anywhere in the script, but the use of var in your code component overrides that, and so jitter is not accessible beyond the “Begin Routine” function, it just shows up later as undefined. So, just remove var.


@dvbridges Thanks a lot! This was in fact causing the issue. It also made me realise that the process of translating the code was not actually so difficult in this instance at least. I translated the rest of the code and it is all working very well now (or so it seems). Thank you so much for helping me through the process of setting this up!

1 Like

Hi, I am using the latest version ( PsychoPy v2021.1) but still having this issue.
I am trying to add the the command line: R1_c1.setPos([t,0]) before in the original one: R1_c1.setPos(Staircase_R1). It works but not as smooth as it was. How can I change that? Thanks!!!

Hey! Could you post this in a separate thread? Helps us keep issues and solutions organized :slight_smile: