collapse

Author Topic: Some more JS - Timer problem  (Read 567 times)

0 Members and 1 Guest are viewing this topic.

Offline Shortie

  • Administrator
  • Authority
  • *
  • Posts: 5710
  • The Ultimate Boss
  • OS:
  • Windows 7Windows 7
  • Browser:
  • Firefox 3.1b3Firefox 3.1b3
    • View Profile
    • Graphics Mayhem
Some more JS - Timer problem
« on: April 22, 2009, 05:14:21 AM »
Some more JS :D:D

Hi

I need a function which does the following

function do-the-timer(state,function-to-call,timer-period);

So that the state can be Stop, Start, Reset-to-Start

The function-to-call can be anything myfunction-1 or myfunction-2 etc

And the time-period just a value in mSecs

I have tried the following but have had no joy as every time I call the function it starts another time hence there are loads of timer events running so instead of calling the myfuction-1 every 5 mins it calls it every time a refresh happens so if you do not do a refresh all is okay but as soon as you do a refresh another instance is started so if you do three refreshes quickly you end up with the original time doing a refresh and at each instance of the three refreshes you get another

Hope this make sense

The calls I have tried are

SetInterval / ClearInterval

And

SetTimeout / ClearTimeout

So any input is apprecisated

Shortie


Thank You, "Guest" For Reading My Post.


Offline SoLoGHoST

  • SMF MOD Expert!
  • Connoisseur
  • *
  • Posts: 2375
  • OS:
  • Windows VistaWindows Vista
  • Browser:
  • Microsoft IE 8.0Microsoft IE 8.0
    • View Profile
Re: Some more JS - Timer problem
« Reply #1 on: April 22, 2009, 11:08:50 AM »
Shortie, there is a huge difference in uppercase and lowercase of setTimeout and SetTimeout and clearInterval and ClearInterval.  Better to use the setInterval() and clearInterval() functions than setTimeout() and clearTimeout() functions.

So you should use clearInterval(variable) before calling the setInterval.   This will work fine, and if there is no interval to clear, than it just moves on down the list of things to do in the function.
Code: [Select]
var daTimer;

function doTheTimer(ms)
{
clearInterval(daTimer);
setInterval('yourFunction(\'functionParameter\')', ms);
daTimer = setInterval('yourFunction(\'functionParameter\')', ms);
}

Hope this helps you.

Offline Shortie

  • Administrator
  • Authority
  • *
  • Posts: 5710
  • The Ultimate Boss
  • OS:
  • Windows 7Windows 7
  • Browser:
  • Firefox 3.1b3Firefox 3.1b3
    • View Profile
    • Graphics Mayhem
Re: Some more JS - Timer problem
« Reply #2 on: April 22, 2009, 12:03:46 PM »
cool will try later

Thank You, "Guest" For Reading My Post.


 


* Search



* Latest Activity.

A GM Wallpaper by NerdBoy
[Yesterday at 07:31:24 AM]


Next Topic Page 1.2 by NerdBoy
[December 15, 2010, 06:28:37 PM]


Windows 8 Wallpaper Concepts by NerdBoy
[December 14, 2010, 09:31:08 PM]


Who can make me a custom mod? by VintageJetBoats
[December 13, 2010, 10:35:47 AM]


December 2010 Uptop Logo Contest by NerdBoy
[December 12, 2010, 07:01:48 PM]


Icon request by NerdBoy
[December 10, 2010, 06:39:27 PM]


Ultimate Weather by NerdBoy
[December 10, 2010, 12:22:41 PM]


General Wallpapers by NerdBoy
[December 10, 2010, 12:17:18 PM]


Logo request by NerdBoy
[December 09, 2010, 08:26:51 AM]


Nerdboy's Birthday by NerdBoy
[December 07, 2010, 06:02:44 AM]