Bunoon: TESS | Manual | Timer

Have you ever used a setInterval() method which you wanted to adjust while its running? Have you ever set one off and lost control of it? Also these problems are a thing of the past, as this section will allow you to create timers that are tracked internally, so if something goes wrong, you can easily stop the timer (or all of them if your not sure).

You can easily assign IDs when creating timers so you can track them yourself, while also allowing you to store the instance of the timer object so you can have better control over it.

Creates a new timer (if allowed) with a specific function call, speed and links it against a unique ID (so that all timers can be controlled).

The main arguments for this function are as follows:

  • oFunction [Object] - States the function that should be used in the timer.
  • nSpeed [Number] - States the speed that the timer should work at (defaults to 1000 milliseconds).
  • bStart [Boolean] - States if the timer should start when initialized (set to true as default).
  • sTimerID [String] - States an ID that the timer should be stored under (for outside access, defaults to next index).

The return control function list is as follows (or null if there has been an error). All the listed functions return a boolean of true/false to state of we have completed the operation:

  • [Start] - Starts the timer.
  • [Stop] - Stops the timer.
  • [Clear] - Clears the timer (stops it and then deletes all the stored details).
  • [SetSpeed] - Sets the speed of the timer.

Below is an example of how to use this function:

var nCounter = 0;


function Counter () {

nCounter += 1;

document.title = "Timer Count: " + nCounter;

};


var oTimer = new $T.Timer.New(Counter, 1000, false, "MyTimer");


oTimer.Start();

Finds a timer (by ID) and starts it.

The main arguments for this function are as follows:

  • sTimerID [String] - The ID of the timer.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var bCompleted = $T.Timer.Start("MyTimer");

Finds a timer (by ID) and stops it.

The main arguments for this function are as follows:

  • sTimerID [String] - The ID of the timer.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var bCompleted = $T.Timer.Stop("MyTimer");

Finds a timer (by ID) and clears it (stops it and then deletes all the stored details).

The main arguments for this function are as follows:

  • sTimerID [String] - The ID of the timer.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var bCompleted = $T.Timer.Clear("MyTimer");

Loops through the timers that have been created and starts any that have been stopped.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var bCompleted = $T.Timer.All.Start();

Loops through the timers that have been created and stops any that have been started.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var bCompleted = $T.Timer.All.Stop();

Loops through the timers that have been created, stops them and then deletes all the stored details.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var bCompleted = $T.Timer.All.Clear();

Changes the maximum number of timers that can be used at any time.

The main arguments for this function are as follows:

  • nMaximum [Number] - States the maximum number of timers that can be used.

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var bCompleted = $T.Timer.All.SetMaximum(20);