Hello
(Updated 17.11.2020: Following is the URL for anyone who want to help me with this: Sign in · GitLab). Any help is very much appreciated!!
In my experiment I have included a Drag and Drop feature (Code by @dvbridges). The Python version in Builder works perfectly, the automatically translated JS code not so much. This will throw back the error:typeError: movePicked is not a function
I have already tried to look for another translation (since I am super duper new to JS and all), and I found nw from @wineandsushi I tried: Click and drag images to lock in a specified area - #6 by wineandsushi. But this also throws back an error: ReferenceError: movePicked is not defined (see picture)
The JS code is as follows:
Begin Experiement:
**Begin Experiement:**
//automatically translated JS code which gives back the Error: typeError: movePicked is not a function
function createPiece(piece, pos, name) {
return new visual.ImageStim(win, {"image": piece.image, "name": name, "size": piece.size, "pos": pos});
}
function drawPicked(picked) {
for (var each, _pj_c = 0, _pj_a = picked, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
each = _pj_a[_pj_c];
each.draw();
}
}
function movePicked(picked, mouseExpIndiv, grabbed) {
if (((grabbed !== undefined) && mouseExpIndiv.isPressedIn(grabbed))) {
grabbed.pos = mouseExpIndiv.getPos();
return grabbed;
} else {
for (var piece, _pj_c = 0, _pj_a = picked, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
piece = _pj_a[_pj_c];
if ((mouseExpIndiv.isPressedIn(piece) && (grabbed === undefined))) {
return piece;
}
}
}
}
//Also **Begin Experiment:** Code from wineandsushi, which gives back the error: ReferenceError: movePicked is not defined
function createPiece(piece, pos, name){
return new visual.ImageStim({win : psychoJS.window,
image: piece.image,
name: name,
size: piece.size,
pos: pos})
}
function drawPicked(picked, draw) {
if (picked.length > 0) {
for(let each of picked) {
each.autoDraw = draw;
}
}
}
function movePicked(picked, mouseExpIndiv, grabbed) {
if (grabbed != 'undefined' && mouseExpIndiv.getPressed()[0] === 1) {
grabbed.pos = mouseExpIndiv.getPos();
return grabbed
} else {
for (let piece of picked) {
if (piece.contains(mouseExpIndiv) && mouseExpIndiv.getPressed()[0] === 1 && grabbed === 'undefined'){
piece.pos = mouseExpIndiv.getPos();
return piece;
}
}
return 'undefined'
}
}
Begin Routine:
//**Begin Routine:**
pieces = [redPieceExInd, greenPieceExInd];
picked = [];
movingPiece = 'undefined';
polygonExpIndiv.setFillColor('undefined');
polygonExpIndiv.setLineColor('undefined');
polygonWeiterExampleIndiv.setAutoDraw(false);
polygonWeiterExampleIndivOn = false;
polygonWeiterExpIndivSelected = false;
polygonWeiterExampleIndiv.setFillColor('undefined');
polygonWeiterExampleIndiv.setLineColor('undefined');
Each frame:
//**Each frame:**
for (let piece of pieces) {
if (piece.contains(mouseExpIndiv) && mouseExpIndiv.getPressed()[0] === 1) {
picked.push(piece)
}
movingPiece = movePicked(picked, mouseExpIndiv, movingPiece);
drawPicked(picked);
if (mouseExpIndiv.isPressedIn(piece)) {
if ((polygonExpIndiv.contains(mouseExpIndiv) && mouseExpIndiv.isPressedIn(redPieceExInd))) {
thisExp.addData("ExampleIndivAnswer", "No");
polygonWeiterExampleIndiv.setAutoDraw(true);
polygonWeiterExampleIndiv.setFillColor([(- 1.0), 0.004, 0.506], "rgb");
polygonWeiterExampleIndiv.setLineColor([(- 1.0), 0.004, 0.506], "rgb");
polygonWeiterExampleIndivOn = true;
} else {
if ((polygonExpIndiv.contains(mouseExpIndiv) && mouseExpIndiv.isPressedIn(greenPieceExInd))) {
thisExp.addData("ExampleIndivAnswer", "Yes");
polygonWeiterExampleIndiv.setAutoDraw(true);
polygonWeiterExampleIndiv.setFillColor([(- 1.0), 0.004, 0.506], "rgb");
polygonWeiterExampleIndiv.setLineColor([(- 1.0), 0.004, 0.506], "rgb");
polygonWeiterExampleIndivOn = true;
}
}
}
if ((polygonWeiterExampleIndivOn && mouseExpIndiv.isPressedIn(polygonWeiterExampleIndiv))) {
polygonWeiterExpIndivSelected = true;
}
if (polygonWeiterExpIndivSelected) {
continueRoutine = false;
}
}
End Routine
//**End Routine::**
piece = drawPicked(picked, false, piece) //added from wineandsushi, but I don't know what it does
polygonWeiterExampleIndiv.setAutoDraw(false);
polygonWeiterExampleIndivOn = false;
polygonWeiterExpIndivSelected = false;
polygonWeiterExampleIndiv.setFillColor('undefined');
polygonWeiterExampleIndiv.setLineColor('undefined');
I don’t quite understand why movePicked is not defined or not a function, because it is defiend in Begin Experiment or BEgin Routine? Can anybody help me with that please?