Sleeping 
Author Message
 Sleeping

I've searched and I've searched.  Is there a sleep
function in JScript that would just make the script stop
execution?  This is what I'm trying to do.

I have a image on the screen.  Another imgae moves
across.  Once they collide, I want to do a dialog between
the two.  the dialog is only an image of a comic balloon
with text inside.
I want an image to appear on the screen, then after say 3
seconds, I want the balloon popup to move over who is
talking and show the next imgae.

I can make the image move.  That's no big deal.  I can
change the text inside the image. Actualy the text is
above the image. The set the z-order property to higher
number than the image.

What I've tried.

I have a global counter set to 0.
When I make the image and the message visible, I check if
the global counter is less than 100;  If not, I increment
the counter and call setTimeout(" same function()",50);  
This doesn't work.  Still too fast.  I even tried chaging
the 100 to 10000.  still fast.

help
Prince



Wed, 08 Sep 2004 01:34:32 GMT  
 Sleeping
The setTimeout should solve your problem. can you post
your code?

I've created a small script that will do what you need.

<SCRIPT>
// Message object holds text and the position on the
screen to show them
function Message(text, left, top) {
        this.text = text;
        this.left = left;
        this.top = top;

Quote:
}

// messageArr holds the messages
messageArr = new Array();

messageArr[messageArr.length] = new Message("text1",10,10);
messageArr[messageArr.length] = new Message
("text2",100,10);
messageArr[messageArr.length] = new Message("text3",10,10);

// showMessage displays current message
function showMessage(currMessage) {
        if (currMessage >= messageArr.length) {
                // no more messages, hide text and image
                document.all
["messageTextDiv"].style.display = "none";
                document.all["messageImage"].style.display
= "none";
          } else {
                // update text div
                document.all["messageTextDiv"].innerHTML =
messageArr[currMessage].text;
                document.all["messageTextDiv"].style.left
= messageArr[currMessage].left;
                document.all["messageTextDiv"].style.top =
messageArr[currMessage].top;
                // update img location
                document.all["messageImage"].style.left =
messageArr[currMessage].left;
                document.all["messageImage"].style.top =
messageArr[currMessage].top;

                currMessage += 1;
                window.setTimeout("showMessage
("+currMessage+");",3000);
        }

Quote:
}

window.onload = function() {
        showMessage(0);

Quote:
}

</SCRIPT>

<DIV id="messageTextDiv" style="z-index:2;
position:absolute;"></DIV>
<IMG id="messageImage" style="position:absolute;"
src="balloon.gif">

Quote:
>-----Original Message-----
>I've searched and I've searched.  Is there a sleep
>function in JScript that would just make the script stop
>execution?  This is what I'm trying to do.

>I have a image on the screen.  Another imgae moves
>across.  Once they collide, I want to do a dialog between
>the two.  the dialog is only an image of a comic balloon
>with text inside.
>I want an image to appear on the screen, then after say 3
>seconds, I want the balloon popup to move over who is
>talking and show the next imgae.

>I can make the image move.  That's no big deal.  I can
>change the text inside the image. Actualy the text is
>above the image. The set the z-order property to higher
>number than the image.

>What I've tried.

>I have a global counter set to 0.
>When I make the image and the message visible, I check if
>the global counter is less than 100;  If not, I increment
>the counter and call setTimeout(" same function()",50);  
>This doesn't work.  Still too fast.  I even tried chaging
>the 100 to 10000.  still fast.

>help
>Prince
>.



Wed, 08 Sep 2004 08:54:49 GMT  
 Sleeping
setTimeout and setInterval are asynchronous -- allowing other
code to execute.  If you want a truly synchronous sleep function
that prohibits other code from executing during this wait
period, try the  following loop technique:

  function sleep(n) {
    var start = new Date();
    while ((new Date() - start) < n) ; // Loop and wait
  }

  alert("Before sleep");
  sleep(3000); // Wait 3 seconds
  alert("After sleep");

But be careful.  Setting a sleep period too high may have adverse
affects in other areas of your code.

Hope this helps,
Jim Rofkar


| I've searched and I've searched.  Is there a sleep
| function in JScript that would just make the script stop
| execution?  This is what I'm trying to do.
|
| I have a image on the screen.  Another imgae moves
| across.  Once they collide, I want to do a dialog between
| the two.  the dialog is only an image of a comic balloon
| with text inside.
| I want an image to appear on the screen, then after say 3
| seconds, I want the balloon popup to move over who is
| talking and show the next imgae.
|
| I can make the image move.  That's no big deal.  I can
| change the text inside the image. Actualy the text is
| above the image. The set the z-order property to higher
| number than the image.
|
| What I've tried.
|
| I have a global counter set to 0.
| When I make the image and the message visible, I check if
| the global counter is less than 100;  If not, I increment
| the counter and call setTimeout(" same function()",50);
| This doesn't work.  Still too fast.  I even tried chaging
| the 100 to 10000.  still fast.
|
| help
| Prince



Wed, 08 Sep 2004 23:46:25 GMT  
 Sleeping
Quote:
> setTimeout and setInterval are asynchronous

That is true but in this case it doesn't really matter. It should
solve his problem.

The sleep function as suggested here will take 100% CPU. It will
prevent the user from doing any action on the page (and will slow down
his computer).


Quote:
> setTimeout and setInterval are asynchronous -- allowing other
> code to execute.  If you want a truly synchronous sleep function
> that prohibits other code from executing during this wait
> period, try the  following loop technique:

>   function sleep(n) {
>     var start = new Date();
>     while ((new Date() - start) < n) ; // Loop and wait
>   }

>   alert("Before sleep");
>   sleep(3000); // Wait 3 seconds
>   alert("After sleep");

> But be careful.  Setting a sleep period too high may have adverse
> affects in other areas of your code.

> Hope this helps,
> Jim Rofkar



> | I've searched and I've searched.  Is there a sleep
> | function in JScript that would just make the script stop
> | execution?  This is what I'm trying to do.
> |
> | I have a image on the screen.  Another imgae moves
> | across.  Once they collide, I want to do a dialog between
> | the two.  the dialog is only an image of a comic balloon
> | with text inside.
> | I want an image to appear on the screen, then after say 3
> | seconds, I want the balloon popup to move over who is
> | talking and show the next imgae.
> |
> | I can make the image move.  That's no big deal.  I can
> | change the text inside the image. Actualy the text is
> | above the image. The set the z-order property to higher
> | number than the image.
> |
> | What I've tried.
> |
> | I have a global counter set to 0.
> | When I make the image and the message visible, I check if
> | the global counter is less than 100;  If not, I increment
> | the counter and call setTimeout(" same function()",50);
> | This doesn't work.  Still too fast.  I even tried chaging
> | the 100 to 10000.  still fast.
> |
> | help
> | Prince



Thu, 09 Sep 2004 05:28:41 GMT  
 Sleeping
Again, I reiterate:

  But be careful.  Setting a sleep period too high may have adverse
  affects in other areas of your code.

setInterval and setTimeout will do what he requires, but a "sleep"
function is what was originally requested:

  Is there a sleep function in JScript that would just make the script
  stop execution?

Cheers,
Jim Rofkar.


| The sleep function as suggested here will take 100% CPU. It will
| prevent the user from doing any action on the page (and will slow down
| his computer).



Thu, 09 Sep 2004 23:55:34 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. wscript.sleep 1 and wscript.sleep 2

2. How to create a sleep in an HTA (wscript.sleep doesn't work in HTA...)

3. How Can I Sleep in HTA, e.g. wscript.sleep?

4. sleep function

5. Sleep-Command

6. sleep/timeout in vbscipt

7. sleeping

8. wscript.sleep does not work

9. sleep funtion

10. How can I do a SLEEP or Pause in VBSCRIPT

11. wait or sleep functionality

12. wait, sleep, ...

 

 
Powered by phpBB® Forum Software