psychopy.org | Reference | Downloads | Github

Unable to convert undefined to a number

URL of experiment: Pavlovia

Description of the problem:

I have an experiment where you have to find a hidden target coin (red). To do this there is a cue that appears then you have to use a rectangular net to respond (drag to where you think the hidden coin is).

I have a code component (net_code) defining the drag and drop capability of the net (builder component is called net_shape) and I think that could be where the problem is based on this error message from the developer tools:

Is there anything in the javascript of the code component net_code that could explain this error?

Hi Lucy,

What is curious here is that it doesn’t look like you are using the .toNumerical method anywhere in your script. Can I please check, is this a relatively new error and, if so, at what point in your commit history would you say the error appeared? (just to try and pin down where this could be coming from)

Thanks,
Becca

It was today- where it says ‘Removed conditions file’

Weirdly when I was working on it on Friday the error was:
TypeError: undefined is not an object (evaluating ‘this._gui’)

I don’t think I had changed anything since then other than adding a conditions file (as this was part of a solution to this error according to another thread) and change the size of the net.

Hope that helps

Hi
I am also getting this error. My experiment was working fine on the pilot last week, and when I went to pilot today to show it to someone, it is now giving this error but I havent made any changes inbetween!

Is there a way to find out which object is undefined, or which line of code it is which is causing this problem?

Thanks, Elle

Hi Elle,

I haven’t been able to solve the error but to see where the error is coming from you want to access the developer tools/console whilst the experiment window is still open.

To access these on mac its option + cmd + j and for Windows it is Ctrl + shift + i

Thanks Lucy,

Im following this thread so if you do figure it out please post so I can try it too :slight_smile:

Opening the developer tools feels like it could help…however, it looks identical to yours!

image

Do you know of anyway to find out which object within my code is undefined?

Yes I will post on here when I find the solution.

I’m not 100% where to look for the undefined variable in the code but I will let you know when I can shed some light on that

Hi Lucy,

I think I have fixed this for my experiment!
Online it didnt like that the position of one of my stimuli was a variable defined in an excel sheet. (Position: $(LR,UD) ) because it meant that at the begining of the experiment there was no position defined for the image.

To get around this I added a piece of code into the problem routine where under Begin Experiment I defined my position variables (LR = 0 & UD = 0) so that the position is never undefined, but once the routine loads it uses the LR and UD variables from the excel sheet.

Hope this makes sense!

2 Likes

That sounds like a neat solution. Thanks!

Hi Elle,

That solved that error for me but am just trying to figure out how to get this to work with out the conditions file ( I am looking to update my stimulus position frame by frame so using a conditions file over rides my code to do this I think). Thanks again for your response though as it helped my understanding of what was going wrong :slight_smile:

Hi,
Hmm yes I think your right a conditions file wont work for what you need.
Maybe within your code for updating the position every frame you could define a starting position in Begin Experiment so that the position is never undefined?

Yes that works without a conditions file now thank you :slight_smile:

So my net_pos_x and net_pos_y are essentially what would be in the conditions file if I did have one. They are now defined at Begin experiment.

Hi, I have come back to this again using a conditions file. Is the syntax for defining the starting position in Java Script (Begin Experiment):

my_stim_pos = 0;
my_other_stim_pos = 0:

I can get rid of the error now (thank you so much!) but I cannot get the conditions file to kick into action so the position throughout the experiment is 0,0.

Hi Becca,

I just wanted to follow this up and let you know that it has now been solved. See above.

1 Like

Hi Lucy,

I am facing a similar issue. How exactly did you manage to get the conditions file to kick into action?

As soon as I implement a custom code to define the position at the beginning of the experiment, it won’t recognise the positions defined in the conditions file anymore.

Thanks,
Nik

Hi,

I think I got rid of trials = None and that helped.
I think there were other things I tried but I can’ remember them off the top of my head. If you show some screenshots of your code I might be able to help. I’m quite new to this myself but I hope my struggles can lead to something useful.

Hi,

I defined my position variable at the beginning of the experiment and then updated it based on the conditions file:

var first_x;
....
first_x = 0;
....
var block1Components;
function block1RoutineBegin(snapshot) {
  return function () {
    //------Prepare to start Routine 'block1'-------
    t = 0;
    block1Clock.reset(); // clock
    frameN = -1;
    continueRoutine = true; // until we're told otherwise
    // update component parameters for each repeat
    singleCue.setPos([first_x, 0]);

firstBlock.xlsx (9.4 KB)

The entire code is accessible on gitlab

Thanks,
Nik

Hi Nik,

As far as I understand, if this an experiment created in builder with a code component what you want to do is put your first_x = 0 in the ‘Begin experiment’ tab and then put the rest of your code in ‘Begin routine’.

This means that at the start of the experiment you will be telling the computer that the value is in fact defined (defined as 0 initially) to remove error. Then as the experiment begins, the builder’s conditions files should take over as they are the default.

Additionally, I remember that to get my experiment to fully commit the changes to the online experiment I had to clear my browser cache on my google chrome.

Hope that helps,

Lucy

Hi Lucy,

thanks for your reply. I tried all that with the builder but unfortunately, it doesn’t work.
The error “unable to convert undefined to a number” is gone as soon as I put an initial value in the ‘Begin experiment’ tab but the builder’s conditions file won’t take over. It just stays at the initial value.

Best,
Nik

The issue is now resolved. It had to do with the empty cells in my condition file.