How to fix that? about cancelTask() ;

Discussion in 'Development' started by HumYaiJang, Apr 7, 2019.

  1. HumYaiJang

    HumYaiJang Spider

    Messages:
    6
    GitHub:
    HumYaiJang
    $task = new PingTask($this, $player);
    $id = $task->getTaskId();
    $this->getScheduler()->cancelTask($id);


    why it cant cancel task?
     
  2. KielKing

    KielKing Zombie

    Messages:
    271
    GitHub:
    kielking
    the task is not scheduled, the default TaskId is -1 (iirc), you must schedule it first, then get the task id
     
    HumYaiJang likes this.
  3. HumYaiJang

    HumYaiJang Spider

    Messages:
    6
    GitHub:
    HumYaiJang
    PHP:

    $this
    ->getScheduler()->scheduleRepeatingTask(new PingTask($this$player), 5);
    schedule with this code?
     
  4. KielKing

    KielKing Zombie

    Messages:
    271
    GitHub:
    kielking
    yes
     
  5. HumYaiJang

    HumYaiJang Spider

    Messages:
    6
    GitHub:
    HumYaiJang
    can you fix this plugin? i'm trying long time and finally it's error :(
     
  6. Emirhan Akpınar

    Emirhan Akpınar Witch

    Messages:
    62
    GitHub:
    EmirhanWSD
    Firstly you should add property.
    PHP:
    /**
     * @var array
     */

    public $taskId = [];

    After add task id to list when you call task.
    PHP:
    $this->taskId[$player->getName()] = $this->getScheduler()->scheduleRepeatingTask(new PingTask($this$player), 5)->getTaskId();

    For cancelling task for specific player.
    PHP:
    if (isset($this->taskId[$player->getName()])) {
         
    $this->getScheduler()->cancelTask($this->taskId[$player->getName()]);
         unset(
    $this->taskId[$player->getName()]);
    }
     
    HumYaiJang likes this.
  7. HumYaiJang

    HumYaiJang Spider

    Messages:
    6
    GitHub:
    HumYaiJang
    Thank you very muck, i just know
     
  8. Emirhan Akpınar

    Emirhan Akpınar Witch

    Messages:
    62
    GitHub:
    EmirhanWSD
    :)
     
  9. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    or simply, in the task class :
    PHP:
    $this->getHandler()->cancel();
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.