Raised This Month: $32 Target: $400
 8% 

set task functionality


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-29-2017 , 10:21   set task functionality
Reply With Quote #1

In the next example function_1 will always return true, shouldn't be more logical to return false since the task already triggered the function and has no reason to exist anymore?

PHP Code:

#define TASK_1      5000

public plugin_init()
{
      
set_task(30.0"function_1"TASK_1)
}

public 
function_1(taskid)
{
      if(
task_exists(TASK_1))
      {
          return 
true 
      
}
      return 
false

__________________

Last edited by Depresie; 09-29-2017 at 10:22.
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-29-2017 , 10:35   Re: set task functionality
Reply With Quote #2

It probably gets destroyed once function_1 returns.
Is there anything wrong with that? Do you really need it to be destroyed before function_1 gets called? What are you exactly trying to do? If you provide a good enough reason for it to be changed then it may as well change.
klippy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 09-29-2017 , 14:32   Re: set task functionality
Reply With Quote #3

KliPPy is right, the task is destroyed after the function's return.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-29-2017 , 17:14   Re: set task functionality
Reply With Quote #4

Well, it would be more logical to be destroyed before the function returns, because from the moment the function is triggered, the respective task does not exist anymore..

One reason in particular for me, is the following case where i have a function with multiple triggers, but don't want it to be executed if there is a task set to execute it

Of course there are workarounds, there always are, but to me, it just doesn't make sense that a task which doesn't exists anymore, to be said that it still exists..

PHP Code:

#define TASK_WAITING_PLAYERS 2000
public plugin_init()
{
       
set_task(45.0"function_check_players"TASK_WAITING_PLAYERS)
}

public 
client_disconnect()
{
     
function_check_players()
}

public 
client_team_changed()
{
     
function_check_players()
}

public 
client_killed()

     
function_check_players()
}

public 
function_check_players()
{
    if(
task_exists(TASK_WAITING_PLAYERS))
         return
   
    
// execute some fancy code

__________________

Last edited by Depresie; 09-29-2017 at 17:24.
Depresie is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-30-2017 , 00:06   Re: set task functionality
Reply With Quote #5

Quote:
Originally Posted by Depresie View Post
Well, it would be more logical to be destroyed before the function returns, because from the moment the function is triggered, the respective task does not exist anymore..
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.

What you are wanting is something more like "trigger function". However, in your case there are probably better ways to do it. Simply use a global variable to control the functionality of the function:

PHP Code:
public DoStuff()
{
    if( 
g_bAllowed )
    {
        
// Main functionality here
    
}
}

public 
TaskToDoStuff()
{
    
g_bAllowed True
    DoStuff
()

__________________
fysiks is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-30-2017 , 05:16   Re: set task functionality
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
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.
I totally agree with this. I'm sure that in most languages that have a library managing timers/delays/tasks contained by an object you would find the same behavior.

Last edited by klippy; 09-30-2017 at 05:16.
klippy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-09-2017 , 08:04   Re: set task functionality
Reply With Quote #7

Quote:
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.
Makes sense, but would be welcome to have it work both ways controlled by a param, but that's up to the devs to decide if it would be worth
__________________
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 10-09-2017 , 13:47   Re: set task functionality
Reply With Quote #8

Just use Fysiks's code or something similar to it. It's a problem solvable with a few lines of code, it rarely matters and would add unnecessary complexity by adding another param.
klippy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-09-2017 , 20:52   Re: set task functionality
Reply With Quote #9

Quote:
Originally Posted by Depresie View Post
Makes sense, but would be welcome to have it work both ways controlled by a param, but that's up to the devs to decide if it would be worth
Adding such a thing is completely unnecessary since the proper alternative is trivial.
__________________
fysiks is offline
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 -4. The time now is 23:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode