Closed AdamRichard21st closed 5 years ago
A task still exists because the callback is not finished itself yet.
There is already a topic about this: https://forums.alliedmods.net/showthread.php?t=301628 This is the key statement:
The task exists until the task is completed. The "task" is defined as running the function (which implies completion). So, the task exists until it has completed what you told it to do which is running the function to completion.
Hey, Klippy, great link, thanks.
Yeah, that makes sense to think in that way. But, I honestly can't imagine a scenario where this behavior is welcomed tho.
Can you give me a scenario where you would actually want to call task_exists
in a task handler(callback)?
If your pointer is inside callback, you tecnically speaking do not need check if task exists, since your code is being executed in callback, confuse no?
Anyway, in topic have a case to use that task exists inside callback, also the solution for this.
Regarding the example in the linked topic: you should move the logic in another function and call that from the callback, passing a bool:fromTask
argument so you know whether to check for task existence.
You shouldn't ever really call callback functions on your own, it's always better to move the shared logic to another function.
Yeah, there's no problem with Fysiks's example at all. I've switched my logic to exactly same solution as soon as I realized task exists till its callback ending.
I feel like it's kinda meaningful when task_exists
is able to dinamically return false depending on context, I mean, tasks are not meant to be stoped from callbacks in anyway, so it's semantically intuitive (to me) to handle some checks at this point.
On my current scenario, I'm re-building my deathmatch based mod, to make it clearer at some points, one of them is avoiding too many handlers (such as checking tasks elsewhere) to do stuff. I just decided to create tasks from some handlers pointing to a single callback where I could actually write a self-dependent block of logic.
Just my thoughts guys, thanks. <3
Hello, guys.
So, that's mostly a question first of all. Could we get
task_exists
function to return false if called from its own task callback?I mean,
task_exists
turns into a more meaningful native when it's able to detect a newer task other than the task itself if called from its callback.Please, read the following code:
Output:
You'll notice that
task_exists
can refer to itself if called from its own callback.