psychopy.org | Reference | Downloads | Github

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!

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.