![]() |
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:
HTML Code:
1HTML Code:
1Now, if I do: PHP Code:
HTML Code:
1It definitely needs to be fixed please!!! |
Agreed.
|
this used to piss me off all the time and I could never figure out how to fix it D:
|
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? |
The first example seems to work fine for me. I'm using a WNPC. Would that make a difference?
|
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.
|
Quote:
Quote:
|
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?
|
Quote:
|
You could use scheduleEvent() alternatively, couldn't you?
|
Quote:
|
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:
|
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. |
I almost find this scary. Sure, there are workarounds, but it's a bit frightening how it loses scope like that.
|
Quote:
|
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. :p |
On a slightly somewhat perhaps related note, I have often had problems where temp.vars lose their value in a for loop.
|
Quote:
PHP Code:
|
Quote:
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. |
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.
|
Here is a script I've had the problem with... it may have to do with function temp vars or something:
PHP Code:
I've had the problem more than once, as well. |
Reviving this thread after a good 3 years in hopes of reminding Stefan that this is still an issue. >.>
|
Quote:
|
I've had it a couple of times. I agree it ****ing annoying.
|
Bump. Are you every going to get around to fixing this Stefan? It's doing my head in.
|
Quote:
I.e. PHP Code:
|
| All times are GMT +2. The time now is 10:13 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.