1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

The task is not working

Discussion in 'Development' started by Hoyee, Jun 4, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    There is no error but task doesn't work. It should be delayed 4second and do Start()

    here is code
    PHP:
    use pocketmine\scheduler\Task;

    class 
    Run extends PluginBase implements Listener{

    public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool {

        
    $command $command->getName();
        
    $sender $sender->getPlayer();

        if ( 
    $command == "tea"){

          
    $task = new time;
          
    $this->getScheduler()->scheduleDelayedTask($task80);

          
    $this->Start();

        }return 
    true;

      }
    PHP:
    class time extends Task{

      public function 
    onRun($currentTick){

      }

    }
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You must add function Run->Start(); to onRun() function, your code will execute the function without delay.
     
    Primus likes this.
  3. BenMenEs

    BenMenEs Creeper

    Messages:
    5
    if you want to check sender class use if(instanceof)
    public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
    if($command->getName() == "tea"){
    if($sender instanceof Player){
    $this->getScheduler()->scheduleDelayedTask(new time($this), 20 * 4);
    return true;
    }
    }
    }

    use path_to_your_main_class\main_class_name;
    use pocketmine\scheduler\Task;
    class time extends Task{
    public function __construct(main_class_name $main){
    $this->main = $main;
    }
    public function onRun($currentTick){
    $this->main->Start(); //calling start() function from main class
    }
    }
     
  4. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Then, It can only work with that I writen in onRun() ??? I think that is not efficient.. Then When I need to use many tasks, Should I need to make new tasks and put methods individually what I want to delay?? Is there only that way?
     
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You can schedule repeating task which will execute your delayed tasks.
     
  6. Primus

    Primus Zombie Pigman

    Messages:
    749
    Love the fact that you can code, but can't use BBCode for your code.
    Let me explain the code you wrote:
    I suggest you to go over the code and see if it makes sense.
     
    GamakCZ likes this.
  7. BenMenEs

    BenMenEs Creeper

    Messages:
    5
    I'm here for the first time
     
  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.