Closed Thread Icon

Topic awaiting preservation: setTimeout X many, all bad. Pages that link to <a href="https://ozoneasylum.com/backlink?for=8200" title="Pages that link to Topic awaiting preservation: setTimeout X many, all bad." rel="nofollow" >Topic awaiting preservation: setTimeout X many, all bad.\

 
Author Thread
Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-01-2002 13:44

Ok, I seem to be having a re-occuring problem with setTimeout's...

Basically, I've got a setTimeout() inside a function that I want different objects to use at the same time. This all works fine and dandy when the first opbect is using the function but when another object starts using the same function at the same time it stops all the timeouts for the previous function.

Example (IE only): http://www.whatever.net.au/~cameron/ozone/slidetest/

I've run into this before a couple of times but I've never found a way around it. Any help or suggestions would be appreciated.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-01-2002 15:30

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

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-2002 15:34

OK, I've dealt with this, and have a work-around that suits me. It uses the dreaded "eval()" function, which raises the hackles of several of our coders here (I won't mention Slime by name ;-) but this may be one of the only really good uses for this function!

What happens is this, if you use variables in the setTimout function, it'll look at the values of those variables at the time it processes! If you've called this function several times, chances are the variables have new values now, so it breaks. If you put the whole setTimeout(...code...) function inside an eval function, like eval(setTimeout(...code...)), then those variables will already be EVALuated, and it should work as expected. I use this at http://www.ozones.com/flourish/ - an example I point to a lot.

Your pal, -doc-

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-01-2002 15:54

Wow, thanks for the quick replys.

Doc, That makes sense. I was thinking that the setTimeout was doing something like that. I'll give it a try. Thanks for the example.

InI, arrr, I think I understand what your proposing but my brain's turning to goo when I try and think of a way to put that into practice..... hmmm... On second thought, I don't think I really understand it at all.

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-01-2002 17:58

Been thinking about what you said above InI.

Let me see if i've got this right:

Have one setInterval running which would check several global var's, one for each object to see if it was active or not.

Some outside condition, say a mouseOver(), would change that var which would register as active on the next setInterval()'s iteration.

When it's active the setInterval would move/alter it untll a limit is reached (limit set in some other var) or some other outside condition changes that global var's state to inactive again.

Something like that?

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 06-01-2002 18:26

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-01-2002 18:31

Cool. That's an interesting way of animating things. I think I'll have to play around with that at some point.

Oh, and what's so bad about the eval() function? I've only just really figured out what it does and I'm liking it a hell of a lot! Why so badd?

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-01-2002 19:18

It's slow and makes code hard to read, and way overused (there is almost always another way to go about doing something that looks cleaner and works faster).

There *are* a few cases where it's necessary, and in those cases it tends to not look so bad, but you really have to be careful.

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-2002 22:22

Yah, InI's method works great, I did this page http://changeminds.com/glassPlay/blobs2.shtml after another marathon discussion we had, where all of our "javascript gurus" got to participate, this multi-rollover page was the result. Bascially, we build an array with the values of which image in an array *should* be showing now, and then on a setInterval we check every image on the page to see if it needs adjusting, and then only change the ones needing it. When you mouseover a link, you don't tell it to switch an image, nothing so crude! Instead you tell it that the image it *should* be showing is #5 in the series, and on mouseout you tell it #1. The setInterval runs all the time, adjusting things as needed.

Your pal, -doc-



[This message has been edited by DocOzone (edited 06-01-2002).]

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 06-02-2002 05:30

Wow, that's downright funky!

It's also fun to try and move around without leaving a trail of movenent behind you. I can invision a series of really nifty puzzle games being made out of something like this. Making the objective to turn all of the board into a certain pattern or a certain colour in the quickest ammount of time. You could even add in 'hot spots' that flagged the change of several areas at once.

« BackwardsOnwards »

Show Forum Drop Down Menu