Closed Thread Icon

Preserved Topic: Any way to cancel queued setTimout events? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=17743" title="Pages that link to Preserved Topic: Any way to cancel queued setTimout events? (Page 1 of 1)" rel="nofollow" >Preserved Topic: Any way to cancel queued setTimout events? <span class="small">(Page 1 of 1)</span>\

 
jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 05-28-2000 09:57

Well, the saga continues on my overly embellished Doc script at http://www.coffman.umn.edu/insider/ <P>By adding a 'done' boolean variable I was able to keep the events seperate, but they still can go loopy if people mouse over too many too quickly, which, sadly, seems to be a common occurrence. All I need now is a way to cancel setTimoouts after the fact. Is there a command to do this or what?

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 05-28-2000 11:35

Well, that would have to be the clearTimout() statement, yep! You need to do two things, first you need to name your timeouts, like...<P>mytimeout = setTimeout('function()', 1000);<P>And then to end it, you need this...<P>clearTimeout('mytimeout');<P>I'm not sure if the single quotes need to be there or not, I don't use this feature too often, I usually use flags in my functions to control these things, Timeouts can be flaky sometimes. (Smoke/drink page is done this way.)<P>

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-28-2000 18:27

yeah, the quotes need to be there... it works like this:<P>identifier = setTimeout("statements to execute", milleseconds_to_wait);<P>clearTimeout(identifier);<P>You can also use the setInterval function, which works the same way, except that it continues to execute the code more than once, at the same interval which you specified. I don't see many people using this... I use it almost all the time.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-28-2000 20:42

Oh, single quotes or double quotes, doesn't matter - both do the same thing in JavaScript.

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 05-31-2000 18:11

How would u use a flag to set up this situation? Is there another way to animate multiple images without using setTimeouts at all? Well, I'm off to check out the smoking/drinking JS.

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 05-31-2000 19:25

Well, spy this javascript snippet:<P>function resetImages()
{for(var i = 1;i < 9;i++)
{clearTimeout('timeout' + i)}
swap(0,0);
swap(1,2);
swap(2,5);
swap(3,8);
swap(4,11);
swap(5,13);
swap(6,21);
swap(7,23);
swap(8,23);
swap(9,23);
done = true}<P>function scoopIn()
{if(done)
{done = false;swap(0,1);
timeout1 = setTimeout('swap(1,4)',25);
timeout2 = setTimeout('swap(2,7)',50);
timeout3 = setTimeout('swap(3,10)',75);
timeout4 = setTimeout('swap(4,12)',100);
timeout5 = setTimeout('swap(5,14)',125);
timeout6 = setTimeout('swap(5,15)',150);
timeout7 = setTimeout('swap(5,16)',175);
timeout8 = setTimeout('swap(5,19);done = true',200)}
else
{resetImages();scoopIn()}
}<P>The bottom function is characteristic of all my rollover functions, its supposed to check to see if swapping is currently occurring (from the done boolean). If it is, then it clears the queue of setTimeouts by running the resetImages function which does a loop and cancels all the possible timeouts (timeouts are named the same in all the rollover functions so I can just call this same function). Then it resets the images to their initial state, changes done to true and returns. Whereby the rollover function calls itself again and SHOULD start over, right? But that's not what's happening. The rollovers are getting more jumbled then ever before. I figure I must be having troubles referencing the setTimeouts or something...<p>[This message has been edited by jiblet (edited 31-05-2000).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-31-2000 19:27

What do you mean by a "flag"?

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 05-31-2000 19:39

I assume Doc just means a boolean variable.

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 06-01-2000 00:32

Yah, real low tech stuff here, like...<P>var do_me_now = 1;<P>...so you can check to see...<P>if (do_me_now) {...}
else {...}<P>And if you set do_me_now to 0 than it won't run! Replace do_me_now with an array like do_me_now[x] and you can track multiple events. Not the most elegant solution, but setTimeout() has a whole bunch of bugs in it on various browsers, simpler to just avoid the problem.
<P>

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 06-01-2000 01:19

Hey Doc, I think you've got the wrong thread in mind...the do_me_now function belongs in the "applets" thread <img border=0 align=absmiddle src="http://www.ozones.com/forum/smile.gif"><P>

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 06-01-2000 13:20

Heh. I work with this programmer, he just loves my variable names. They can come out almost like poetry if you choose them right. <P>if (do_me_now && babybaby) { go_for_it(); }
else if (headache) { backrub(); }
else { sleep(); }<P>Heh.<P>

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-01-2000 21:09

lol, I'd like to see those functions!<P>I have a friend who comes up with the wackiest variable names; occasionally he's been upset at the QBasic variable name character limit of something like 32 or 64 characters.

« BackwardsOnwards »

Show Forum Drop Down Menu