Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 08-10-2009, 12:49 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Agreed.
__________________
Reply With Quote
  #3  
Old 08-10-2009, 12:59 AM
Frankie Frankie is offline
xChugxLifex
Frankie's Avatar
Join Date: Feb 2008
Location: New York
Posts: 1,610
Frankie is a jewel in the roughFrankie is a jewel in the rough
Send a message via AIM to Frankie Send a message via MSN to Frankie
this used to piss me off all the time and I could never figure out how to fix it D:
__________________
*Sum41Freeeeek
*Frankie
Reply With Quote
  #4  
Old 08-10-2009, 02:27 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Definitely needs to be fixed. I had a system that, since I had no clue about what I was doing wrong, had to not use a loop, which sucked because only a number was changing.
Also, maybe sleep could not be interrupted (or keep going) when using another function?
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #5  
Old 08-10-2009, 02:31 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
The first example seems to work fine for me. I'm using a WNPC. Would that make a difference?
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #6  
Old 08-10-2009, 04:00 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Yea I noticed this a long time ago myself. And I don't remember reporting it either; my attitude towards the lack of updates is probably why.
__________________
Reply With Quote
  #7  
Old 08-10-2009, 10:42 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Tigairius View Post
I spent hours trying to figure this out.
Should've come to me sooner!

Quote:
Originally Posted by LoneAngelIbesu View Post
The first example seems to work fine for me. I'm using a WNPC. Would that make a difference?
I assume you were doing it on serverside, obviously it would never loose the player scope clientside.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #8  
Old 08-10-2009, 12:35 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
The loss of scope when using sleep has been a problem with the script engine since day one, I am not sure how easy it is to fix if it is some kind of delayed scheduling. Does it also occur while using waitfor?
__________________
Skyld
Reply With Quote
  #9  
Old 08-10-2009, 01:18 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Skyld View Post
Does it also occur while using waitfor?
I'm fairly certain it does not.
__________________
Reply With Quote
  #10  
Old 08-10-2009, 01:23 PM
FreezeBurnX FreezeBurnX is offline
Registered User
FreezeBurnX's Avatar
Join Date: Jul 2003
Location: Belo Horizonte - Brasil
Posts: 296
FreezeBurnX is on a distinguished road
Send a message via AIM to FreezeBurnX Send a message via Yahoo to FreezeBurnX
You could use scheduleEvent() alternatively, couldn't you?
Reply With Quote
  #11  
Old 08-10-2009, 01:32 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by FreezeBurnX View Post
You could use scheduleEvent() alternatively, couldn't you?
Yes, but scheduleevent is inconvenient because it is harder to keep track of loops.
__________________
Reply With Quote
  #12  
Old 08-10-2009, 01:47 PM
FreezeBurnX FreezeBurnX is offline
Registered User
FreezeBurnX's Avatar
Join Date: Jul 2003
Location: Belo Horizonte - Brasil
Posts: 296
FreezeBurnX is on a distinguished road
Send a message via AIM to FreezeBurnX Send a message via Yahoo to FreezeBurnX
Maybe there's a way to store the reference to the player? I don't know exactly how it is done on graal, but something amongst the lines...
PHP Code:
function onPlayerEnters(eventPlayer) {
  
testFunc(eventPlayer);
}

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

Reply With Quote
  #13  
Old 08-10-2009, 03:20 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Yes you can also do temp.pl = player and then use temp.pl.
Currently triggered events are keeping care of the player scope (scheduleevent, trigger, etc.) but not functions that suspend the script executing (sleep, waitfor). This has always been like that, but might be good to fix it someday.
Reply With Quote
  #14  
Old 08-10-2009, 05:25 PM
TESTRETIS TESTRETIS is offline
Zvarri!
TESTRETIS's Avatar
Join Date: Oct 2003
Posts: 970
TESTRETIS has a spectacular aura about
I almost find this scary. Sure, there are workarounds, but it's a bit frightening how it loses scope like that.
Reply With Quote
  #15  
Old 08-10-2009, 06:03 PM
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
Quote:
Originally Posted by FreezeBurnX View Post
Maybe there's a way to store the reference to the player? I don't know exactly how it is done on graal, but something amongst the lines...
PHP Code:
function onPlayerEnters(eventPlayer) {
  
testFunc(eventPlayer);
}

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

Yes, that's basically what I did, but it can cause a lot of problems for people who aren't aware of this problem.
__________________


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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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

Forum Jump


All times are GMT +2. The time now is 09:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.