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

Solved How can i share variables on task

Discussion in 'Development' started by Qeis2007, Aug 25, 2018.

  1. Qeis2007

    Qeis2007 Witch

    Messages:
    70
    GitHub:
    FrostingBita
    Can i share variables from Main to Task?
    For example, i have $php on Main and i want to use that variable on Task too
     
  2. RyanShaw

    RyanShaw Witch

    Messages:
    69
    You send the variable when you're sending the task and you then construct that variable in your task class.
    PHP:
            $task = new Task($this,$player);//Player is the variable i want in my task. Also you can put more variables here.
            
    $this->getScheduler()->scheduleDelayedTask($task,20); 
    And then construct it
    PHP:
        public function __construct($plugin,$player){
                    
    $this->plugin $plugin;
                    
    $this->player $player;//here
        
    }
          public function 
    onRun(int $tick){
         
    //do whatever 
         
    var_dump($this->player->getName());
          }
     
  3. NinjazZtine

    NinjazZtine Creeper

    Messages:
    2
    GitHub:
    ninjazztine
    called to undefined variable
     
  4. xLeakDev Enzo

    xLeakDev Enzo Spider Jockey

    Messages:
    38
    GitHub:
    nya-enzo
    $player variable must be defined
     
    NinjazZtine likes this.
  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.