Graal Forums  

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

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, 10:42 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
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
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
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
  #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, 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
  #14  
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
  #15  
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
  #16  
Old 08-11-2009, 02:52 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Well, at least this way people will be dissuaded from using sleep, which increases the chance of weird and even more confusing things happening to scripters, like race conditions.

That said, a bug should never be a feature, so fix it please.
Reply With Quote
  #17  
Old 08-11-2009, 02:54 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
On a slightly somewhat perhaps related note, I have often had problems where temp.vars lose their value in a for loop.
Reply With Quote
  #18  
Old 08-11-2009, 02:56 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
Quote:
Originally Posted by DustyPorViva View Post
On a slightly somewhat perhaps related note, I have often had problems where temp.vars lose their value in a for loop.
Are you declaring them inside the loop?

PHP Code:
temp.0;

for (
temp.item : array) {
  echo(
b);
  
++;

has always worked for me
__________________
Reply With Quote
  #19  
Old 08-11-2009, 02:58 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by DustyPorViva View Post
On a slightly somewhat perhaps related note, I have often had problems where temp.vars lose their value in a for loop.
Is the script getting suspended in the middle (i.e., sleep, waitfor), or is it just a straight-up for loop?

I have literally no technical data on how GScript works, such as threading, etc. or how scripts execute based on what they are waiting for (i.e., do all of them lock if one is waiting on I/O), so I can only speculate.

Even if you aren't suspending the script, it's possible that another script runs and pushes some variables out of the memory, or perhaps the garbage collector is going haywire for some reason.
Reply With Quote
  #20  
Old 08-11-2009, 02:59 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
It's not exactly that simple of a scenario. I can't do so right now, but I will pull up an example of a script where I have had the problem.
Reply With Quote
  #21  
Old 08-11-2009, 04:06 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Here is a script I've had the problem with... it may have to do with function temp vars or something:
PHP Code:
function HitWall(k,speed,wall) {
  
temp.foo k;
  for (
temp.i=0;i<speed;i+=1/16) {
    if (
onwall2(check[k][0]+vecx(k)*i,check[k][1]+vecy(k)*i,check[k][2],check[k][3])) {
      if (
k in {0,2}) {
        
player.+= vecy(k)*i;
        
player.int(player.y+.5);
      } else {
        
player.chat k;
        
player.+= vecx(k)*i;
        
player.int(player.x)+.5;
      }
      break;
    }
  }

var foo handles the value proper, var k does not. Player chat will return 0.

I've had the problem more than once, as well.
Reply With Quote
  #22  
Old 08-03-2012, 12:03 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Reviving this thread after a good 3 years in hopes of reminding Stefan that this is still an issue. >.>
Reply With Quote
  #23  
Old 08-03-2012, 12:42 AM
Pandar Pandar is offline
Babylon Co-Manager
Pandar's Avatar
Join Date: Jan 2007
Location: New York
Posts: 68
Pandar has a spectacular aura aboutPandar has a spectacular aura about
Quote:
Originally Posted by devilsknite1 View Post
Reviving this thread after a good 3 years in hopes of reminding Stefan that this is still an issue. >.>
This, this, forever more, holy ****, it's one of the most ANNOYING things in GS2.
__________________
R.I.P. Graal (1998 - 2004)
Reply With Quote
  #24  
Old 08-03-2012, 12:48 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
I've had it a couple of times. I agree it ****ing annoying.
__________________
Reply With Quote
  #25  
Old 11-29-2013, 08:10 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Bump. Are you every going to get around to fixing this Stefan? It's doing my head in.
__________________
Reply With Quote
  #26  
Old 12-14-2013, 11:59 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
Bump. Are you every going to get around to fixing this Stefan? It's doing my head in.
Store the player object before calling sleep.

I.e.

PHP Code:
temp.pl player;
sleep(5);
echo(
temp.pl.account); 
This same issue occurs when loading TServerPlayer objects as well.
__________________
Quote:
Reply With Quote
Reply


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 08:27 AM.


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