HighDots Forums  

how to block the value of a variable?

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss how to block the value of a variable? in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris
 
Posts: n/a

Default how to block the value of a variable? - 07-22-2005 , 08:41 AM






Hi,

I want to show pictures each 5 seconds, so i define first the present time:

tempsreel= new Date()
trh=tempsreel.getHours()
trm=tempsreel.getMinutes()
trs=tempsreel.getSeconds()
te=parseInt(trh)*3600+parseInt(trm)*60+parseInt(tr s)

Now i calculate 5 seconds further:
nte=te+5

Finally, the new picture must appear five seconds later, but i can't compare
"te" with "nte" because the difference will always be 5. What i want is to
block the value of "nte", so when the real time equals "nte", then next
picture ...

Any idea how?
Thanks
Chris






Reply With Quote
  #2  
Old   
Kimmo Laine
 
Posts: n/a

Default Re: how to block the value of a variable? - 07-25-2005 , 05:19 AM






"Chris" <sdqfsd (AT) qdvqsd (DOT) cv> kirjoitti
viestissä:9tudneAG-vNWZX3fRVnyhA (AT) scarlet (DOT) biz...
Quote:
Hi,

I want to show pictures each 5 seconds, so i define first the present
time:

tempsreel= new Date()
trh=tempsreel.getHours()
trm=tempsreel.getMinutes()
trs=tempsreel.getSeconds()
te=parseInt(trh)*3600+parseInt(trm)*60+parseInt(tr s)

Now i calculate 5 seconds further:
nte=te+5

Finally, the new picture must appear five seconds later, but i can't
compare
"te" with "nte" because the difference will always be 5. What i want is to
block the value of "nte", so when the real time equals "nte", then next
picture ...

Any idea how?
Thanks
Chris

How about utilizing the timer functions setInterval or setTimeout. It seems
setInterval is precisley what you need.

For example: you define the function that displays the picture
function show_my_cool_pic(){
// do some magik here
}

// And then start a timer that calls the function periodically

timer_id = setInterval("show_my_cool_pic()",5000); //5000 is 5 seconds as
milliseconds.


Now the function show_my_cool_pic() should be called each five seconds.
If you ever want to stop it, then call

clearInterval(timer_id);

--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears

eternal.erectionN0 (AT) 5P4Mgmail (DOT) com




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.