View Single Post
  #17  
Old 01-07-2010, 07:44 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by Chompy View Post
Sleep() will not return and break everything after. Sleep() will freeze/pause the script for the given time, and then continue.


Also..


that is like saying you can't put sleep() in any loops (timeout, scheduleevent, while, for) ;D

PHP Code:
function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
setTimer(1);
}

function 
onTimeout() {
  echo(
this.var1);
  
sleep(5);
  echo(
this.var2);
  
setTimer(1);
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
scheduleEvent(1"Timeout2"0);
}

function 
onTimeout2() {
  echo(
this.var1);
  
sleep(5);
  echo(
this.var2);
  
scheduleEvent(5"Timeout2"0);
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
  
this.loop = function() {
    echo(
this.var1);
    
sleep(5);
    echo(
this.var2);
    
sleep(1);
    
this.loop();
  };
  
  
this.loop();
}

// above functions identical to the script below:

function onCreated() {
  
this.var1 "This is echoed when timeout events occurs.";
  
this.var2 "This is echoed 5 seconds later";
  
  while(!
waitfor(this"timeout"1)) {
    echo(
this.var1);
    
sleep(5);
    echo(
this.var2);
  }

When I used sleep() in a while loop, it broke .
Reply With Quote