Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can I add a thread in Pocketmine?

Comments in 'Plugin Development' started by PopChicken, Jul 22, 2015.

  1. PopChicken
    Offline

    PopChicken New Member

    Joined:
    Apr 19, 2015
    Posts:
    6
    Minecraft User:
    None
    I know in Pocketmine-API, there is a abstract class called Thread. And I should extends it and add the function "start()". But it doesn't work.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should override the run() function in the thread class, and use $thread->start() to start the thread.
  3. PopChicken
    Offline

    PopChicken New Member

    Joined:
    Apr 19, 2015
    Posts:
    6
    Minecraft User:
    None
    thanks, but it print upload_2015-7-22_15-33-12.png

    and here is my code:
    upload_2015-7-22_15-34-46.png
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
  5. PopChicken
    Offline

    PopChicken New Member

    Joined:
    Apr 19, 2015
    Posts:
    6
    Minecraft User:
    None
    I have tried to add sth... But the error still occured.....
  6. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    392
    I guess the object $t goes out of scope and gets destroyed by the garbage collector before it finishes executing. Make a property $t in the class ttm and assign the thread object to $this->t and see if it works. That way there will always be a reference to the object.
    TigerHix and PEMapModder like this.

Share This Page

Advertisement