1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

timer

Discussion in 'Development' started by b3st_Thunder78, Jul 4, 2019.

  1. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
    Hello how can I create a timer so seen in a minecraft plugin that delays happening

    $sender->sendMessage ("Hi");
    2 seconds later
    $sender->sendMessage("Hi 2");

    So how is that possible?
     
  2. Gianluxx

    Gianluxx Slime

    Messages:
    94
    GitHub:
    Gianluxx
    ScheduleDelayedTask

    ScheduleRepeatingTask
     
  3. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
    how does ma build into the code?
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
  5. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
    Sorry I still do not kapire can someone scream the code so that after 2 seconds ... so a 2 second interval?
     
  6. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    lmao
     
    b3st_Thunder78 likes this.
  7. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
  8. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
    Im so stupid
     
  9. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    That is the funniest thing I've seen all day, "kapieren" does not translate to English that way, use "understand" instead.

    Here's the code using a ClosureTask:
    PHP:
    $sender->sendMessage("Hi");
    $seconds 2;
    $this->getScheduler()->scheduleDelayedTask(new \pocketmine\scheduler\ClosureTask(
         function(
    int $currentTick) use ($sender): void {
              
    $sender->sendMessage("Hi 2");
         }
    ), 
    20 $seconds);
     
    Muqsit and b3st_Thunder78 like this.
  10. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.