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

Getting value from sub class to main class

Discussion in 'Development' started by XdmingXD, Mar 19, 2017.

  1. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Hello!
    I created two class : main and Task
    I have called Task in main class and I used this in my main class and Task class :
    PHP:
    public function onNothing() {
                    
    $this->called++;
                    if(
    $this->called == 1) {
                        
    $task = new Task($this$player);
                        
    $this->task[] = $task;
                        
    $h $this->getServer()->getScheduler()->scheduleRepeatingTask($task20);
                        
    $task->setHandler($h);
                        
    $this->task[$task->getTaskId()] = $task->getTaskId();
    Task class (sub class)
    PHP:
    public function __construct(main $plugin Player $player) {
              
    $this->plugin $plugin;
              
    $this->player $player;
              
    $this->seconds 0;
              
    parent::__construct($plugin);
          }
    So I want to get $seconds to my main class
    As you can see I already use __construct so if I use __construct again in my main class,the server can't not find constructor
    I also tried $this->plugin->seconds
    but how do you define $this->plugin is?
    Anyone can help QAQ
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    using $this->plugin->seconds is a bad idea when you want to run concurrent events
    i would highly suggest looking into using &
     
  3. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    What do you mean &?
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    look it up PHP and sign
    you can construct the task with a reference which you set it in an array somewhere
     
    0x15f likes this.
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It's called passing by reference. You'll be accessing the live array instead of a copied array.
     
  6. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Sorry but I am not good at english
    Can you do me an example of "&" please?
     
    Last edited: Apr 4, 2017
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Sure
     
  8. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    uhmm i have read that webside and I don't understand it well....
    Also, i only see access variable between one class...
     
  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.