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

Wrong with timer

Comments in 'Plugin Development' started by Kripak, Oct 6, 2015.

  1. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    What's wrong with timer ?

    Attached Files:

  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    How do we know? We don't even know what's supposed to happen and what the error is (if there is even one).
    Also, you're checking if
    PHP:
    $this->time === 20
    which will not happen if the value is already 20 and you make your value smaller before you check if it is 20. You should probably check if it is 0.

    Also, the RepeatingTask is running every 1200 ticks when it should be 20 (at least I think?)
    PEMapModder likes this.
  3. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    I want to limit the use of the opening event. Event can be used every 20 seconds. How to do it ?
    Last edited: Oct 6, 2015
  4. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    i would
    PHP:
    switch($this->time){
    case 
    20:
    //code
    break;
  5. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    Crash..

    Attached Files:

  6. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    How will that help? And a switch with one case is useless. You're better off using an if statement.
    PEMapModder likes this.
  7. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Which event? And is this for each player or not?
    Last edited: Oct 6, 2015
  8. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    The player can be used every 20 seconds event. This limitation is for each player.
  9. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Tip: use === instead of ==
    And if you don't know how do $this->time--; (I'm not sure if it exists), do $this->time = ($this->time-1);
  10. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    + You didn't declared variables $this->p and $this->time so add
    PHP:
    public $p;
    public 
    $time;
    after class declaration
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There is another way round this, but this is one that you can use.
    PHP:
    private $mod;
    public function 
    onRun($ticks){
      if(!isset(
    $this->mod)) $this->mod $ticks 20;
      if((
    $ticks 20) === $this->mod){
        
    // run your code
      
    }
    }
    This code is run every 20 ticks, assuming that you run the task every tick. (I have no idea at all why you scheduled it at 1200 ticks)
    So actually, do you simply want it to be run every 20 ticks (1 second)? You should just put the code directly with no checks, and schedule for every 20 ticks.
    Or do you want 20 seconds? Then 400 ticks.
    Or do you want to run it at the 20th time ONLY? In that case, your code is right except you should check time === 0 instead of 20.
    They are exactly the same, and actually $var-- is faster than your method (negligibly).

    BTW, your timer class should be with namespace MagicBed not namespace Timer. Namespace and class names are different.

Share This Page

Advertisement