Force end of routine 0.5 seconds after mouse click

Hi!
I work on a task where participants have to click on a specific sequence of blocks that were previously highlighted. Clicked blocks change their color after mouse click for 0.1 seconds. I adapted my code based on the following post: Forcing End of Routine One Second After Mouse Click
The code works fine, but not online. The following message appears:
ReferenceError: endTime is not defined.
Here is my code block in each frame:

Python:
for rec in rectangles:
if mouse.isPressedIn(rec):
rec.fillColor = "black"
clicked = True
if rec.name == corrAns:
endTime = t
thisExp.addData('correct', 1)
else:
thisExp.addData('correct', 0)

if clicked and t > endTime + 0.5:
continueRoutine = False

JS:
for (var rec, _pj_c = 0, _pj_a = rectangles, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
rec = _pj_a[_pj_c];
if (mouse.isPressedIn(rec)) {
rec.fillColor = "black";
clicked = true;
if ((rec.name === corrAns)) {
endTime = t;
thisExp.addData("correct", 1);
} else {
thisExp.addData("correct", 0);
}
}
}
if ((clicked && (t > (endTime + 0.1)))) {
continueRoutine = false;
}

Can anybody help me to solve this problem?

Maybe online t is not recognize? Try with a custom made clock with core.Clock() and it should work just fine

tandy

That JS isn’t auto translated.

You have endTime+0.5 in the Python and endTime + 0.1 in the JavaScript

I use t all the time in online experiments.

endTime = t is only being set if your answer is correct but is being checked whenever the rectangle is clicked.

Dear @tandy and @wakecarter

Thank you very much for your helpful replies!

I tried to replace t by core.Clock(). This does not work under normal conditions and also not online (see my code below; message: endTime is not a constructor)

I restructured my code. I put endTime = t after mouse.isPressedIn.
This code works, but not online. Here again I get the message that endTime is not defined.

grafik

It would be great if you had further ideas I could try.
Thank you very much!

Here is my code I used with core.Clock (with 0.1 ms added to endTime):

Python:

for rec in rectangles:
    if mouse.isPressedIn(rec):
        clicked = True
        rec.fillColor = "black"
        endTime = core.Clock()
        if rec.name == corrAns:
            thisExp.addData('correct', 1)
        else:
            thisExp.addData('correct', 0)


if clicked and core.Clock() > endTime + 0.1:
    continueRoutine = False

JS:

for (var rec, _pj_c = 0, _pj_a = rectangles, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
    rec = _pj_a[_pj_c];
    if (mouse.isPressedIn(rec)) {
        clicked = true;
        rec.fillColor = "black";
        endTime = new core.Clock();
        if ((rec.name === corrAns)) {
            thisExp.addData("correct", 1);
        } else {
            thisExp.addData("correct", 0);
        }
    }
}
if ((clicked && (new core.Clock() > (endTime + 0.1)))) {
    continueRoutine = false;
}