ID:143117
 
I'm not thinking too clearly today. TL;DR at the bottom. I don't know how to deal with this in BYOND since we can't refer to other running procs by some kind of ID, but maybe one of you.


Lets say there is Proc X.

Proc X basically is tasked with Creating "A", sleeping for 5 seconds, and then deleting A. If A already exists when Proc X is called, it means A needs to be deleted early, so it deletes it.

Not bad right.

So basically, a player invokes Proc X, which creates A, it sleeps for 5 seconds, and deletes A. Cool.


But, there will be situations in which during the 5 seconds that Proc X sleeps, the player invokes a new instance of Proc X again. Thus the player wants to kill A early, and A is deleted by the new Proc X. When the old proc X awakens, it finds A is already gone, so it does nothing and disappears.

But then, there are the situations in which a player calls Proc X twice when the original proc X sleeps.

So basically:

Proc X is called,

A is create.

Player calls Proc X again,
so A is deleted early.

Player calls Proc X AGAIN, and a new A is made.

**But this time the player wants A to last the full 5 seconds. This will not happen, because the original Proc X from the beginning now awakens.

Original Proc X deletes A.

Chaos.



TL;DR: Can sleeps be interrupted?
I don't think sleep can be interupted, but I suppose you could make a work around. Depending on what A is. If it is an object then you could give it a variable to keep track of how long it has been inexistence. Then check that var before you delete it.
In response to Drumersl
A isn't an object. And that solution doesn't work because it doesn't allow for early termination anyway.
That doesn't make any sense. Are your variables static? Are you searching for the object before you create another? Use spawn() instead of sleep(), too.
In response to Obs
If it isn't an object then how are you "creating" it? Why NOT make it an object, and then give the proc to the object, which would then immediately cease when it's deleted, solving this problem. Or call a proc on the object to delete itself after a period of time. Alternatively: have a (global) timestamp when the not-object is not-created, then a local timestamp in the proc. If the two don't match, then have the proc do nothing.
In response to Garthor
It's a GUI element.
In response to Obs
Nothing preventing you from wrapping the handling of that element in a datum.
Have the sleeping and deleting proc attached to the object? So when you delete the object the proc trying to delete is then gone anyway. Won't have to worry about checking a whole bunch of variables or trying to halt any procs yourself.
In response to Dever
Dever wrote:
Have the sleeping and deleting proc attached to the object? So when you delete the object the proc trying to delete is then gone anyway. Won't have to worry about checking a whole bunch of variables or trying to halt any procs yourself.


Like I said, there is no actual object to delete, the proc isn't attached to an object.



Anyway, I've since found a decent way to do this by assigning a pseudo ID to the proc, so this thread is effectively over.