Clock in JavaScript for Pavlovia

Hello,

I am having trouble in translating a Python code to Java. First, I describe the Py script.

In the experiment, participants have to make 3 consecutive presses (with a total maximum time of 2.5 seconds). If they don’t make the 3 presses, the time expires and the next routine starts. The three presses correspond to 3 routines:

Press1:

#Begin Routine

timer = core.Clock()
max_time = 2.5

and

#Each Frame

if timer.getTime()>max_time:
    continueRoutine = False

Press 2 and Press 3 (separately)

#Each Frame

if timer.getTime()>max_time:
    continueRoutine = False

However, using the automatic translation in JS, I get the following error:

TypeError: core.Clock is not a constructor

As far as I understand, reading also other topics here, JS does not really like core.Clock(). Is there another way of doing it though?

Here is the repository for the experiment:

2 Likes

Instead of core.Clock(), try:

timer  = new util.Clock();
3 Likes

Hi @PsyLing @GioP @Michael
for countdown timer, I used “timer = new util.Clock()”; instead of core.Clock(),
and it worked for me but I got new error message " * ReferenceError: minutes is not defined

how can I translate the Python to JS to define minutes?
following is the code I used to define minutes in JS:
else {
minutes = Number.parseInt((timeRemaining / 60.0));
seconds = Number.parseInt((timeRemaining - (minutes * 60.0)));
timeText1 = (((minutes.toString() + “:”.toString()) + seconds.toString()) + " minutes".toString());
}

Hi gshejaeya,

if you want you can follow a thread i just open about displaying a clock online:

Hope that my code or any reply might be of any help!
tandy

Thank you very much :grinning:.