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

RepeatingTask in Main class

Comments in 'Plugin Development' started by Bluplayz, Dec 28, 2015.

  1. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    I want to use a Countdown in function so here is my Example:

    PHP:

    public function GameTask($ticks/*or else xD*/){

    $this->countdown 1;
    $this->countdown--;
    $this->getServer()->broadcastMessage("Noch ".$this->countdown);
    }

    I hope that it works , please comment with examples :D

    i want to ignore getOwner() because i hate to write getOwner() xD so plz how i can make it without create a new class :D
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    You're Lazy.
    you need to create a class to do it.
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Yep and you cant store the variable $this->countdown = 1; in the tick function
  4. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    why ? xD is there no way ?

    why i cant?
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Because your countdown gets the every second reset to the value
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In PHP, one class can only extend one other class (or extend nothing). Due to the PocketMine class autoloader, there SHOULD only be one class per file.
    if you think that calling getOwner() every time is annoying, add
    PHP:
    $owner $this->getOwner();
    in the beginning will allow you to use $owner directly afterwards.

    As of PHP 7, you can use anonymous classes, but PocketMine doesn't officially support PHP 7 yet.
  7. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    If you really dont want to create a new class, use CallbackTask(Look at ASR)
    Bluplayz likes this.
  8. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    But it's deprecated
    PEMapModder likes this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You MUST NOT use CallbackTask in plugins.
  10. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    Okay thx i will use CallbackTask ! Thx
  11. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    No

    PHP:

    If(!isset($countdown1)){
    $countdown1 60;
    }

    $countdown1--;

  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    #Facepalm
    It is deprecated, i.e. it will get removed in future versions.
  13. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Yes, its deprecated, but you can just copy it and add it into your plugin (and modify it a little) :p
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Plugins must use tasks that extend PluginTask. So you should use CallbackPluginTask instead ;)
  15. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Yeah, that what i mean actually ;)

Share This Page

Advertisement