Unknown position units: undefined

URL of experiment:

Description of the problem:
I’m attempting to move my study online with Pavlovia. I am not familiar with Javascript, so I’m having some difficulty translating my code components into js. Specifically, I am getting the following error:

Unfortunately we encountered the following error:

  • when getting the position of an object
  • when converting a position to pixel units
  • unknown position units: undefined

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

I have isolated the error to this every frame code:

var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
if ((! drag_in_process)) {
    if (mouse.getPressed(stim_t)) {
        clicked_stimulus = stim_t;
        drag_in_process = true;
    }
}
if (_pj.in_es6(true, mouse.getPressed())) {
    if (drag_in_process) {
        clicked_stimulus.pos = mouse.getPos();
    }
} else {
    if ((clicked_stimulus !== null)) {
        for (var dest, _pj_c = 0, _pj_a = [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
            dest = _pj_a[_pj_c];
            if (dest.contains(mouse.getPos())) {
                current_dest = dest;
                clicked_stimulus.pos = current_dest.pos;
            }
        }
        clicked_stimulus = null;
    } else {
        drag_in_process = false;
    }
}
if ((! drag_in_process)) {
    if (mouse.getPressed(stim_t)) {
        clicked_stimulus = stim_t;
        drag_in_process = true;
    }
}
if (_pj.in_es6(true, mouse.getPressed())) {
    if (drag_in_process) {
        clicked_stimulus.pos = mouse.getPos();
    }
} else {
    if ((clicked_stimulus !== null)) {
        for (var dest, _pj_c = 0, _pj_a = [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
            dest = _pj_a[_pj_c];
            if (dest.contains(mouse.getPos())) {
                current_dest = dest;
                clicked_stimulus.pos = current_dest.pos;
                clicked_stimulus = null;
            }
        }
    } else {
        drag_in_process = false;
    }
}

The participant is supposed to click and drag the stimulus onto a grid, where it snaps into place. Please let me know where I have gone wrong in my code.

I am adding in my python code that has worked perfectly on local computers.

if not drag_in_process:
    if mouse.isPressedIn(stim_t):
        clicked_stimulus = stim_t
        drag_in_process = True
        break

if True in mouse.getPressed():
    if drag_in_process:
        clicked_stimulus.pos = mouse.getPos()

elif clicked_stimulus is not None:
    for dest in [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8]:
        if dest.contains(mouse.getPos()):
            current_dest = dest
            clicked_stimulus.pos = current_dest.pos
    clicked_stimulus = None

else:
    drag_in_process = False

if not drag_in_process:
    if mouse.isPressedIn(stim_t):
        clicked_stimulus = stim_t
        drag_in_process = True
        break

if True in mouse.getPressed():
    if drag_in_process:
        clicked_stimulus.pos = mouse.getPos()

elif clicked_stimulus is not None:
    for dest in [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8]:
        if dest.contains(mouse.getPos()):
            current_dest = dest
            clicked_stimulus.pos = current_dest.pos
            clicked_stimulus = None

else:
    drag_in_process = False

Thank you!

1 Like

I think what it’s saying is that it’s either not getting sensible information from mouse.getPos(), or it doesn’t know what units mouse.getPos() is in. I’m not sure why in either case. What type of units are you using?

I have the units in the experiment settings set to height, and all components set to use unit settings from experiment settings.

Height units might be buggy for online studies: Unexpected behavior with height units between online and local versions

If you can, try switching to a different type of unit (norm, pix, w/e) and see if that fixes it.

Ok, I’ll try that and let you know if it works.

I tried adjusting the unit settings to norm and I got the same error. I think the larger error is coming from the fact that I’m trying to code a drag and drop of the stimuli. Something about the .pos or mouse.getPos or mouse.getPressed is causing the issue I think. However, I’m still not sure that the auto-translated JS code created by builder will support drag and drop even with a few minor adjustments.

Here is the full code I have for the drag and drop part:

Python code - begin routine:

stimuli = [stim_t]
clicked_stimulus = None
current_dest = None
drag_in_process = False
target_t = d4
target_t_x = target_t.pos[0]
target_t_y = target_t.pos[1]

JS code - begin routine:

stimuli = [stim_t];
clicked_stimulus = null;
current_dest = null;
drag_in_process = false;
target_t = d4;
target_t_x = target_t.pos[0];
target_t_y = target_t.pos[1];

Python code - every frame:

if not drag_in_process:
    for stimulus in stimuli:
        if mouse.isPressedIn(stimulus):
            clicked_stimulus = stimulus
            drag_in_process = True
            break

if True in mouse.getPressed():
    if drag_in_process:
        clicked_stimulus.pos = mouse.getPos()

elif clicked_stimulus is not None:
    for dest in [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8]:
        if dest.contains(mouse.getPos()):
            current_dest = dest
            clicked_stimulus.pos = current_dest.pos
    clicked_stimulus = None

else:
    drag_in_process = False

if not drag_in_process:
    for stimulus in stimuli:
        if mouse.isPressedIn(stimulus):
            clicked_stimulus = stimulus
            drag_in_process = True
            break

if True in mouse.getPressed():
    if drag_in_process:
        clicked_stimulus.pos = mouse.getPos()

elif clicked_stimulus is not None:
    for dest in [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8]:
        if dest.contains(mouse.getPos()):
            current_dest = dest
            clicked_stimulus.pos = current_dest.pos
            clicked_stimulus = None

else:
    drag_in_process = False

JS code - every frame:

var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
if ((! drag_in_process)) {
    for (var stimulus, _pj_c = 0, _pj_a = stimuli, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
        stimulus = _pj_a[_pj_c];
        if (mouse.getPressed(stimulus)) {
            clicked_stimulus = stimulus;
            drag_in_process = true;
        }
    }
}
if (_pj.in_es6(true, mouse.getPressed())) {
    if (drag_in_process) {
        clicked_stimulus.pos = mouse.getPos();
    }
} else {
    if ((clicked_stimulus !== null)) {
        for (var dest, _pj_c = 0, _pj_a = [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
            dest = _pj_a[_pj_c];
            if (dest.contains(mouse.getPos())) {
                current_dest = dest;
                clicked_stimulus.pos = current_dest.pos;
            }
        }
        clicked_stimulus = null;
    } else {
        drag_in_process = false;
    }
}
if ((! drag_in_process)) {
    for (var stimulus, _pj_c = 0, _pj_a = stimuli, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
        stimulus = _pj_a[_pj_c];
        if (mouse.getPressed(stimulus)) {
            clicked_stimulus = stimulus;
            drag_in_process = true;
        }
    }
}
if (_pj.in_es6(true, mouse.getPressed())) {
    if (drag_in_process) {
        clicked_stimulus.pos = mouse.getPos();
    }
} else {
    if ((clicked_stimulus !== null)) {
        for (var dest, _pj_c = 0, _pj_a = [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
            dest = _pj_a[_pj_c];
            if (dest.contains(mouse.getPos())) {
                current_dest = dest;
                clicked_stimulus.pos = current_dest.pos;
                clicked_stimulus = null;
            }
        }
    } else {
        drag_in_process = false;
    }
}

Python code - end routine:

stim_t_x = stim_t.pos[0]
stim_t_y = stim_t.pos[1]
if (stim_t_x == target_t_x) and (stim_t_y == target_t_y):
    stim_t_outcome = 1
else:
    stim_t_outcome = 0

JS code - end routine:

stim_t_x = stim_t.pos[0];
stim_t_y = stim_t.pos[1];
if (((stim_t_x === target_t_x) && (stim_t_y === target_t_y))) {
    stim_t_outcome = 1;
} else {
    stim_t_outcome = 0;
}

The Python code works as is, regardless of the unit settings. I tried decomposing the JS code piece by piece, but I wasn’t able to figure out a way to code a drag and drop in JS.

Weird. There must be a disagreement in the coordinate systems being used in JavaScript, but if even setting it to pixels doesn’t work, I don’t know how. See if this thread is of any help to you: Error in a loop of images in online version only

I found that thread already along with a couple others that were relevant. Unfortunately, the changes I’ve made to my code haven’t worked yet.

Hi Ben!
I encountered the same problem and error message as you did while trying to incorporate a drag and drop system with items snapping into place just like yours…

My units are set on “height”. It ended up working when I deleted all uses of .contains and only used mouse.getPressed() to check if the mouse was unclicked (mouse.getPressed()[0] == 0).

Instead I only called the mouse by mouse.isPressedIn() and mouse.getPos().

To be honest it’s possible that something else got it to work so if you want to have a look my code is called “DragTry” by the name of “Josse” on Pavlovia.

All the best!

Hi did you figure that out. I meet the same problem, I provide my code below, my task is when you click two stimulus, the position of these stimulus changed. And I meet the same problem.

if (clicked_stimuli.length === 2) {
        let stim1, stim2;
        [stim1, stim2] = (function() {
            var _pj_a = [], _pj_b = [A1_ex2, A2_ex2, B1_ex2, B2_ex2, C1_ex2, C2_ex2, bl1, bl2, bl3];
            for (var _pj_c = 0, _pj_d = _pj_b.length; _pj_c < _pj_d; _pj_c++) {
                var s = _pj_b[_pj_c];
                if (clicked_stimuli.includes(s.name)) { // assuming _pj.in_es6 is equivalent to Array.includes
                    _pj_a.push(s);
                }
            }
            return _pj_a;
        })();

        // Swap positions
        let tempPos = stim1.pos;
        stim1.pos = stim2.pos;
        stim2.pos = tempPos;
        clicked_stimuli = [];
        setTimeout(() => {}, 500);
        A1_border = [(- 1), (- 1), (- 1)];
        A2_border = [(- 1), (- 1), (- 1)];
        B1_border = [(- 1), (- 1), (- 1)];
        B2_border = [(- 1), (- 1), (- 1)];
        C1_border = [(- 1), (- 1), (- 1)];
        C2_border = [(- 1), (- 1), (- 1)];
        Dim1_border = [(- 1), (- 1), (- 1)];
        Dim2_border = [(- 1), (- 1), (- 1)];
        Dim3_border = [(- 1), (- 1), (- 1)];
        if (ex_outline2.contains(bl1.pos)) {
            black_1_color = [0.0745, 0.35, 0.0745];
            black_1_border = [0, 0, 0];
        } else {
            black_1_color = [(- 1), (- 1), (- 1)];
            black_1_border = [(- 1), (- 1), (- 1)];
        }
        if (ex_outline2.contains(bl2.pos)) {
            black_2_color = [0.0745, 0.35, 0.0745];
            black_2_border = [0, 0, 0];
        } else {
            black_2_color = [(- 1), (- 1), (- 1)];
            black_2_border = [(- 1), (- 1), (- 1)];
        }
        if (ex_outline2.contains(bl3.pos)) {
            black_3_color = [0.0745, 0.35, 0.0745];
            black_3_border = [0, 0, 0];
        } else {
            black_3_color = [(- 1), (- 1), (- 1)];
            black_3_border = [(- 1), (- 1), (- 1)];
        }
    }
    if (
    (bl1.pos[0] === -0.295 && bl1.pos[1] === 0.17) &&
    (bl2.pos[0] === -0.08 && bl2.pos[1] === -0.205) &&
    (bl3.pos[0] === -0.52 && bl3.pos[1] === -0.215)) {
        if_press5 = 0;
    } else {
        if_press5 = 1;
        ex_space_text2 = "Press space to continue";
    }