Click to See Complete Forum and Search --> : some sort of regulator


Da Warriah
12-15-2002, 02:45 PM
ok, heres my situation: i have a thing with basically an infinite loop, something like this:

var first = 1;
var second = 2;

if (first==1){
first++;
second--;
}
if (first==2){
first--;
second++;
}

but i need some sort of regulator so it doesnt seriously slow down the page...ive tried setTimeout and setInterval, but i cant really understand how they work, and they dont seem to make any difference...is there any way i could make it search to see if these are true, say once every second or so?

Sceiron
12-15-2002, 02:52 PM
Why not put the code that needs running in its own function and use setTimeout() to schedule it every 500 ms or so?

Charles
12-15-2002, 03:30 PM
[I']ve tried setTimeout and setInterval, but i cant really understand how they work.See http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm#1203669 for the details concerning window.setInterval and http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm#1203758 for window.setTimeout.

Da Warriah
12-15-2002, 07:39 PM
so if i put that code inside something like function looping() { }, and the setTimeout("looping()",1000); - it should work, calling the function every second??