Quiz

 
 
Picture of David Ha
Endless Looping
 

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: -
Picture of David Ha
Re: Endless Looping
 

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

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Endless Looping
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
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.
 
Average of ratings: -
Picture of David Ha
Re: Endless Looping
 

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;

}

...........

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Endless Looping
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers
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.
 
Average of ratings: -