Error: When converting an object to its numerical form, unable to convert the object to a number

URL of experiment: Pavlovia, Pavlovia

I am currently running a visual N-back task where the participants view a grid with white squares that appear at different locations. However, when I deploy it online, I get this error:
image

I have seen from other threads that it is likely caused by how JS treats the coordinates, but I have no idea how I can employ a fix for this. It is urgent that I get this fixed as soon as possible, because I have an honours thesis student depending on it for data collection. Any help would be appreciated.

Mark

Hello,

you need to show us the code that you use to show the grid.

Best wishes Jens

Hi Jens,

Would this be the JS script? Because I did this in Builder.

Mark

Hello Mark,

well, I usually trust the auto-translate, so Python-code please. If you surround the Python-code by triple ` it is properly formatted.

Best wishes Jens

Hi Jens,

So there are multiple spots that do this, since I have the grid in the instructions, and in three separate blocks of N-Back tasks.

The first instructions:

InstructionsClock = core.Clock()
instructions = visual.TextStim(win=win, name='instructions',
    text='Welcome to the experiment!\n\nIn this task you will be presented with a 3 x 3 grid of squares. These squares will appear like this:',
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
image_3 = visual.ImageStim(
    win=win,
    name='image_3', 
    image='resources/grid.png', mask=None,
    ori=0.0, pos=(0, 0), size=(0.6, 0.6),
    color=[1,1,1], colorSpace='rgb', opacity=None,
    flipHoriz=False, flipVert=False,
    texRes=128.0, interpolate=True, depth=-1.0)

Then, the instructions give a visual example of what the white squares will look like. Incidentally, the error does not actually occur within this code for some reason. It’s only once it gets into the first N-Back experiment.

instructions_3Clock = core.Clock()
text = visual.TextStim(win=win, name='text',
    text='In this task, white squares will appear within this grid, like this:',
    font='Open Sans',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0, 
    color='white', colorSpace='rgb', opacity=None, 
    languageStyle='LTR',
    depth=0.0);
polygon = visual.Rect(
    win=win, name='polygon',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(-0.2, 0.2),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000, 1.000, 1.000],
    opacity=None, depth=-1.0, interpolate=True)
polygon_2 = visual.Rect(
    win=win, name='polygon_2',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(0, 0.2),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000, 1.000, 1.000],
    opacity=None, depth=-2.0, interpolate=True)
image_2 = visual.ImageStim(
    win=win,
    name='image_2', 
    image='resources/grid.png', mask=None,
    ori=0.0, pos=(0, 0), size=(0.6, 0.6),
    color=[1,1,1], colorSpace='rgb', opacity=1.0,
    flipHoriz=False, flipVert=False,
    texRes=128.0, interpolate=True, depth=-3.0)
polygon_3 = visual.Rect(
    win=win, name='polygon_3',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(0.2, 0.2),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000, 1.000, 1.000],
    opacity=None, depth=-4.0, interpolate=True)
polygon_4 = visual.Rect(
    win=win, name='polygon_4',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(-0.2, 0),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=None, depth=-5.0, interpolate=True)
polygon_5 = visual.Rect(
    win=win, name='polygon_5',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(0, 0),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=None, depth=-6.0, interpolate=True)
polygon_6 = visual.Rect(
    win=win, name='polygon_6',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(0.2, 0),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=None, depth=-7.0, interpolate=True)
polygon_7 = visual.Rect(
    win=win, name='polygon_7',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(-0.2, -0.2),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=None, depth=-8.0, interpolate=True)
polygon_8 = visual.Rect(
    win=win, name='polygon_8',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(0, -0.2),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=None, depth=-9.0, interpolate=True)
polygon_9 = visual.Rect(
    win=win, name='polygon_9',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0.0, pos=(0.2, -0.2),
    lineWidth=1.0,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=None, depth=-10.0, interpolate=True)
text_2 = visual.TextStim(win=win, name='text_2',
    text='During this task, the white squares will appear at different locations. Sometimes the squares will appear in the same location consecutively. You will be required to press the SPACEBAR if the white square appears in the same place consecutively. For example if the square was in the left down corner on trial 1 and then it appeared in the same location on trial 2, press SPACEBAR. Otherwise, do not respond. If you have understood these instructions, press the SPACEBAR to continue.\n\nNote that if you wish to abort this study at any time, you can do so by pressing the ESC key.',
    font='Open Sans',
    pos=(0, 0), height=0.04, wrapWidth=None, ori=0.0, 
    color='white', colorSpace='rgb', opacity=None, 
    languageStyle='LTR',
    depth=-11.0);
key_resp = keyboard.Keyboard()

This is where the error starts:

N_back_1_TrialClock = core.Clock()
grid_lines = visual.ImageStim(
    win=win,
    name='grid_lines', 
    image='resources/grid.png', mask=None,
    ori=0, pos=(0, 0), size=(0.6, 0.6),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0)
target_square = visual.Rect(
    win=win, name='target_square',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0, pos=[0,0],
    lineWidth=1,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=1, depth=-1.0, interpolate=True)
fixation_2 = visual.TextStim(win=win, name='fixation_2',
    text='+',
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-2.0);
response = keyboard.Keyboard()

Something that I noticed is that in builder, I have it set up so that the position = $location, as defined by the excel spreadsheets that I’m using. But in this, the code is working out to pos=[0,0].

Hello,

well, it is usually sufficient to show only that part that is not working. :wink: I guess

target_square = visual.Rect(
    win=win, name='target_square',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0, pos=[0,0],
    lineWidth=1,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=1, depth=-1.0, interpolate=True)

should be

target_square = visual.Rect(
    win=win, name='target_square',
    width=(0.15, 0.15)[0], height=(0.15, 0.15)[1],
    ori=0, pos=(0,0),
    lineWidth=1,     colorSpace='rgb',  lineColor=None, fillColor=[1.000,1.000,1.000],
    opacity=1, depth=-1.0, interpolate=True)

[-brackets instead of (-parentheses.

Best wishes Jens

Hi Jens,

That’s really odd. Why would it be deployed that way when I coded it in builder?

Mark

Hello,

I have no idea. Did you specify it manually in the parameter-settings of the component? And more important does it solve the problem?

Best wishes Jens

Hi Jens,

I am not quite sure how that happened. I tried changing the coordinates in the excel file for one of the experiments to (0,0) instead of [0,0] to see if it helped, and it didn’t. It comes out the same in the Python code regardless. And I tried implementing that change in the code, and then deploying it online, and it unfortunately didn’t solve the problem.

Mark

Hello Mark,

When I create a toy-experiment, the PsychoPy-code looks like this:

# update component parameters for each repeat
polygon.setPos(locpos)

polygon is the name stimulus-component. locpos is the column-name in an Excel-file. The locations are specified as (.1,.1), for example.

grafik

The auto-translated JavaScript-code looks as follows:

// update component parameters for each repeat
polygon.setPos(locpos);

It might be helpful to create a toy-example. See if this runs, and then determine the differences between your toy-example and the real experiment. Editing the PsychoJS-code is not advised since manual changes will be over-written (same for manual PsychoPy-edits).

Best wishes Jens

Thanks Jens,

I’ll look into this.

Mark

UPDATE:

This problem has been fixed. The issue here was that the variable coding the location of where the square would appear was “location”. In PsychoPy, this isn’t a problem, and it will implement it properly. When you convert into JavaScript version of PsychoPy, though, “location” is a protected keyword. I simply changed this variable name in any of my excel files to “nback_position”, and did the corrections in the programming so that it calls $nback_position and not $location, and it works perfectly now.

Leaving this comment about the solution for anybody else that might have this problem in the future.

Mark

Hello Marc,

Good to know. I would not have thought of it. I have the habit of using lowercaseUppcase for variable-names to prevent name-conflicts. Other naming styles will probably also work.

Best wishes Jens