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

Remaining time

Discussion in 'Development' started by GOdly, Dec 1, 2016.

  1. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    I have a new idea about my plugins. And I want to know how to use Task to count the Remaining time of sth. Example, I have a THING with 4 hours and 4 hours later that THING auto disappear.
    Anyone have that code ??
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Define "THING".

    If you are counting in hours, don't use tasks. Use time() instead. Tasks are for frequent schedules up to seconds or even ticks.
    Server lag will delay the task to a large extent if you use scheduler tasks. Server restarts will even cancel the scheduler tasks. Do not rely on them for tasks with low frequency.

    When you start the timer, store time() + 3600 * 4, which is the timestamp when the timer should stop.

    If you want to execute something 4 hours later, start a repeating task that, for every tick/second/period, check if time() > storedTimestamp. If yes, your timer has expired and you have to reset the timer and execute the task.
     
  3. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Some bits of pseudocode:
    PHP:
    //main class
    func onStartTimer(){
    $endAt time() + 3600 4//current time in secounds + 4hours in secounds
    //maybe save it into some file in order to retain it after restart
    BlahServerObject->blahGetScheduler()->blahRepeatingLag(new YourTask($this$endAt)); //don't overdo the repeating ticks though
    }
    //task class
    //blah constructor saves $endAt
    onRun($currentTick){ //was it onRun??
    if($this->endAt time()){
    //do your things after 4hrs in here
    //BlahStopTask
    }
    }
    Sorry for the lack of indenting i threw this together on mobile
     
    GOdly and HimbeersaftLP like this.
  4. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    Okay, I got it :)
     
  5. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    Thank for your opinion
     
  6. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    What can getNested() function do ? I dont know how it use for. It so confusing.
    I want to set a .yml file like this
    Code:
    - Something:
         - Somepeople
         - AnotherPeople
     
  7. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Hm you should open a new thread, but anyways:
    PHP:
    //write 
    ConfigObject->set("Something", ["Somepeople""AnotherPeople"]);
    //read
    $var ConfigObject->get("Something"); //Will return the array we set earlier
    //or give SomePeople and AnotherPeople values
    //write 
    ConfigObject->set("Something", ["Somepeople" => 5"AnotherPeople" => 6]);
    //read
    $var ConfigObject->get("Something.Somepeople"); //Will return 5
    We basically set an array instead of a single value.
    If you don't know what an array is: http://php.net/manual/en/language.types.array.php
     
    GOdly likes this.
  8. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    thanks u
     
  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.