Endless Looping

Endless Looping

by David Ha -
Number of replies: 4

The Quiz module enters into a looping when a timer reaches the 3 second mark.  No matter what a student does, the screen keeps looping over and over.  the only way to get out is to close the browser.

My setup is:

Moodle 1.6.2
MySQL 5.0.24
PHP 5.0.4
Windows Server 2003 w/ IIS 6

Browsers:  IE 6, IE 7, FireFox 1.5+
O/S: Mac (OS X or later), Windows XP, Windows 2000

Average of ratings: -
In reply to David Ha

Re: Endless Looping

by David Ha -

I fixed it.  Change line 16 in timer.js located in /mod/quiz to:

    if(quizTimerValue == 0)  {

The orginal value is:

    if(quiztTimerValue <= 0) {

smile

In reply to David Ha

Re: Endless Looping

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Are you sure?

I changed it because if, for some reason, the timer does not get pinged when quizTimerValue is exactly zero. For instance if it only runs with 1001 milliseconds left, and then not again until there are -1 milliseconds left, then the redirect will never happen.

I am sure <= is safer.
In reply to Tim Hunt

Re: Endless Looping

by David Ha -

Hmmm... I see your logic.  How about this:

var submitted = 0;

function countdown_clock(theTimer) {

var timeout_id = null;

// @EC PF : current client time

var ec_now_epoch = new Date().getTime();

// @EC PF : time left according to client

quizTimerValue = Math.floor( (ec_quiz_finish - ec_now_epoch) /1000 );

if ((quizTimerValue <= 0) && (!submitted)) {

clearTimeout(timeout_id);

var ourForm = document.forms['responseform'];

ourForm.timeup.value = 1;

if (ourForm.onsubmit) {

ourForm.onsubmit();

}

ourForm.submit();

submitted = true;

}

...........

In reply to David Ha

Re: Endless Looping

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Ah! I understand the problem now.

If the the form submission takes longer than 1 second, then the timer fires again, and the form gets submitted again.

So the important thing is to stop the

timeout_id = setTimeout("countdown_clock(theTimer)", 1000);

line of code running again after the form is submitted.

I think that the easiest way to do that is to just put in a

return;

inside the if statement. After the

ourForm.submit();

line. I've checked this fix in.