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

How to do action all 10 seconds

Comments in 'Plugin Development' started by jjmc, Feb 3, 2016.

  1. jjmc
    Offline

    jjmc New Member

    Joined:
    Oct 18, 2015
    Posts:
    41
    Hi,
    I'm making a minigame and need things like a start counter.
    Which is the most performant way to make such a counter in a PocketMine plugin?
    For example, run Message A after 10 seconds, ...
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    if($this->time == 0) $this->time = 0?
    applqpak and PocketKiller like this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    if($this->time 0){
       
    $this->time--;
    } else {
       
    # Send message and stop destroy this task
    }
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It's not! Your code will be repeated after 10 seconds will be passed, every single second. This what player would see:
    PHP:
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    The game has started!
    And how the code can be true?
    applqpak and PocketKiller like this.
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    DID YOU KNOW : That you're resetting $time to 0 when it is 0? and using $this->time-- to make it -1?
  6. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Sory I Forgot Some Thing :)
    This IS True
    PHP:
    public $time 0;
    public 
    $pla 0;

    public function 
    onRun($tkck){//$this->time--;
    if($this->pla == 1){
    $this->time--;
    if(
    $this->time == 0){//-----------------------
    // code
    $this->pla 0;
    }}
    }
    // How Can Start Time !
    $this->time 10;
    $this->pla 1;
    //
    true :)
    Last edited: Feb 3, 2016
    Primus likes this.
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    do you know what you're doing? No
    applqpak and Primus like this.
  8. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Yes I Know
    You Can Test IT
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Again, you created infinity loop. (Don't point out that it can be cancelled from other class)
    applqpak and PocketKiller like this.
  10. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Test IT :)
  11. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    If I test it, nothing will happen.
  12. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    I USE This For My Games
    PHP:
    public $time 0;
    public 
    $pla 0;

    public function 
    onRun($tkck){//$this->time--;
    if($this->pla == 1){
    $this->time--;
    if(
    $this->time == 0){//-----------------------
    // code
    $this->pla 0;
    }}
    }
    // How Can Start Time !
    $this->time 10;
    $this->pla 1;
    //
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    applqpak likes this.
  14. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Run this script.
    PHP:
    <?php

    $timer 
    = new Timer();

    for(
    $i 0$i 50$i++){
       
    $timer->onTick($i 20);
    }

    class 
    Timer {

       public 
    $time 10// # Ten seconds when something will happen!
      
       
    public function onTick($currentTick){
         
    $this->time--;
         if(
    $this->time == 0){
           
    $this->log("10 Seconds passed!");
        
           
    $this->time 0;
         } else {
           
    $this->log("".(($currentTick 20)));
         }
       }
      
       public function 
    log($msg){
         echo 
    "".$msg."</br>";
       }
      
    }

    ?>

    Result
    Code:
    0
    1
    2
    3
    4
    5
    6
    7
    8
    10 Seconds passed!
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    
    applqpak likes this.
  15. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Nice
    But My Code is easy :)
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    That code was made to test yours :D
    applqpak likes this.
  17. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    if($this->time == 0){$this->log("10 Seconds passed!");
    $this->time = 0;
    } else {
    Time == 0 ?
    10 sec passed
    And This IS Not yours
    It's a clear 100%
    I Think You Have Some Problem With Your Code
    I Didnot see Your Code
    All Your Code IS Err
    I've Express
    I just see Spoiler
    Last edited: Feb 3, 2016
    Omar2s2 likes this.
  18. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    his code is completely right.
  19. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    It's a clear 100%
    How Can To Be True !
    Last edited: Feb 3, 2016
    Omar2s2 and Primus like this.
  20. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    I Think You Have eye For see it
    Nope.
    Omar2s2 likes this.

Share This Page

Advertisement