Working autosave, but need help to finalize it

 From:  Michael Gibson
11150.17 In reply to 11150.16 
Hii Moi3dFan, I think maybe you're getting multiple timers going.

Probably the very first thing that should be done inside function SetAutosaveTimer() is to clear any previous timer, by doing:

code:
if ( AutosaveTimer )
{
    clearInterval( AutosaveTimer );
    AutosaveTimer = false;
}


If Autosave is 0 then it's probably better to exit out right after that, currently it sets up a timer and then will clear it out at the end.

So maybe more like this:

code:
				function SetAutosaveTimer()
				{
					// Clear any existing timer.
					if ( AutosaveTimer )
					{
						clearInterval( AutosaveTimer );
						AutosaveTimer = false;
					}

					Autosave = moi.command.getOption( 'Autosave', true); // return autosave time (ms) from ini (180000 = 3 min)
					AutosaveIncremental = moi.command.getOption( 'AutosaveIncremental', true); //return AS mode (false)

					// If Autosave is turned off, exit without setting any timer up.
					if ( Autosave == 0 )
						return;

					AutosaveTimer = setInterval(function() {
						if (AutosaveIncremental) { 
							moi.command.execCommand('IncrementalSave');
						} else { 
							moi.command.execCommand('Save');
						}
					}, Autosave);
				}