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

Solved Help in Scheduler required

Comments in 'Plugin Development' started by MyNameIsTriXz, Dec 1, 2015.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Hey guys I need help, I want to add a counter in the scheduler I do it so: Add in task a function called $this->plugin->tick(); which gets triggered every second, in my main plugin I just do public function tick(){ which should include a count, Id like to have count = 5; but where can I store the count variable, I mean when I store it in the tick function the count gets set every second to 5.... Any ideas?
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    i don't understand what are you tring to do :/
    hoyinm14mc likes this.
  3. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Are you trying to make a timer/countdown?
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $this->count++;
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Yep, but I dont know where to have that variable ($countOITC = 5;) because when I store it in the tick it gets reset every time its called
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    And where can I store the $countOITC = 5; variable? I mean when I have it in the tick it gets reset every time its called...
  7. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I want to know where can I store the variable $countOITC = 5; when I store it in the function which gets called every second it resets of course to 5; but I want that it counts down so where need I store the variable?
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Put the variable in your main class or the task class, it doesn't matter. Schedule a repeating task for each second. Within the task class do:
    PHP:
     $count--;
    // or
    $count++;
    depending on how you want the timer to count.
    MyNameIsTriXz likes this.
  9. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Yep
    I know already, but where to store the var $count = 5; ?
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You can store it in your main class or the task class. It doesnt matter.
  11. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    When
    When I store it just at onEnable(){ or in public class Main extends PluginBase(){ it says that it is undefined -.-
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You need to define the variable's visibility. Learn about it here: http://php.net/manual/en/language.oop5.visibility.php
  13. Ragnok123
    Offline

    Ragnok123 Banned

    Joined:
    Sep 14, 2015
    Posts:
    21
    Minecraft User:
    Ragnok123
    Try $count->++; It's actually works for me
  14. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Thats not even correct syntax, it will just cause a crash.
    And that isnt his issue. The issue is that he doesnt know how to access a class member from another class.
    MyNameIsTriXz likes this.
  15. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    why =5 ???????
    do you need to set the var $count to 5 each second?
    you can store $count in a public var
    PHP:
    class yourClass{

    public 
    $count 0;

    public function 
    tick(){
    $this->count 5//nosense
    }

    Last edited: Dec 1, 2015
  16. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    When I store the var public $countOITC = 5; right after that class Main extends PluginBase{ it also crashes ;-;
  17. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Nope, it sjould get cpunted 5 times before the player gets teleported (countdown)
  18. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I want that it counts down and I DONT want to have it set to 5 every tick :D
  19. cake23
    Offline

    cake23 Active Member

    Joined:
    Aug 10, 2015
    Posts:
    124
    Minecraft User:
    TheEnd
    Maybe this helps: https://forums.pocketmine.net/threads/creating-a-timer-with-tasks.11098/
  20. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I already gave you the answer. Creating a repeating task and $timer--; every second.

Share This Page

Advertisement