Hello everyone,
in my online experiment I had to present a timer on screen in the mm:ss format (mm = minutes, ss = seconds). While i had no problem coding It using phyton I had some problem with Javascript. I have written this code:
In the begin routine tab:
timer_tutorial_s = new util.Clock();
timer_tutorial_m = new util.Clock();
timer_tutorial_m.add(29.5);
tutorial_timestring = "00:00";
In the each frame tab:
tutorial_time_s = timer_tutorial_s.getTime();
tutorial_time_m = timer_tutorial_m.getTime();
tutorial_second = (tutorial_time_s % 60);
tutorial_minute = (tutorial_time_m / 60);
if ((tutorial_second <= 9.5)) {
second_tutorial_timestring = ("0" + tutorial_second.toFixed(0));
} else {
if (((tutorial_second > 9.5) && (tutorial_second < 10))) {
second_tutorial_timestring = "10";
} else {
if (((tutorial_second >= 10) && (tutorial_second <= 59.5))) {
second_tutorial_timestring = tutorial_second.toFixed(0);
} else {
if (((tutorial_second > 59.5) && (tutorial_second < 60))) {
second_tutorial_timestring = "00";
}
}
}
}
if ((tutorial_minute < 0.4917)) {
minute_tutorial_timestring = "00";
} else {
if (((tutorial_minute >= 0.4917) && (tutorial_minute < 9.4917))) {
minute_tutorial_timestring = ("0" + tutorial_minute.toFixed(0));
} else {
if ((tutorial_minute >= 9.4917)) {
minute_tutorial_timestring = tutorial_minute.toFixed(0);
}
}
}
tutorial_timestring = ((minute_tutorial_timestring + ":") + second_tutorial_timestring);
And then there is a text component with $tutorial_timestring as text, set tu update every frame.
Although the code seems to be working I wonder if someone has any suggestion to improve It, maybe using less line of code.
Thank you,
tandy