View Single Post
  #1  
Old 08-10-2009, 12:04 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Sleep() drops scope!

I know this has been reported before, but I couldn't find it, so I'm going to report it here again. It's definitely something to fix in the NPC-Server.

I have a level NPC that joins to a class, inside of the class I have:
PHP Code:
function onPlayerEnters() {
  
testFunc();
}

function 
testFunc() {
  for (
temp.i=1;temp.i<4;temp.i++){
    
sendrpgmessage(temp.i);
    
sleep(1);
  }

It sends the RPG message to me as:
HTML Code:
1
If I remove the sleep from the for loop, it will return:
HTML Code:
1
2
3
Which is correct.

Now, if I do:
PHP Code:
function onPlayerEnters() {
  
testFunc();
}

function 
testFunc() {
  for (
temp.i=1;temp.i<4;temp.i++){
    
findplayer("Tigairius").sendrpgmessage(temp.i);
    
sleep(1);
  }

It returns:
HTML Code:
1
2
3
No problem! (Thanks Ziro for helping me figure that out.) Sleep is causing the function to lose scope of the player. I spent hours trying to figure this out. Time I could have spent progressing further in the script!

It definitely needs to be fixed please!!!
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote