Another Timer techinical question

  • Englisch

Das nächste Update wird zwischen Montag, dem 24. September und Mittwoch, dem 26. September 2018 verfügbar sein. Sorry für die große Verzögerung!

  • angriff schrieb:

    If I start a timer then kill it. I know from another thread that you cannot restart it if I kill it. Therefore, it is best to pause it.
    It depends: re-creating a new timer when you need it (after having killed a previous timer) may be fine too. May even be better if you need an initial delay.

    angriff schrieb:

    The question is if I kill it and I have an action to restart the event method can I use the timer all over again? I would think you could but knowing may save me hours of testing. Thanks
    You gave the answer yourself already: "you cannot restart it if I kill it" (aside: I do not understand what you mean by "I have an action to restart the event method").
    __________
    My plug-ins: Planks 'n Beams, GPS, UPS, Weather control, Plugin Central, RWGui (GUI back-end), Bank (Money back end)
  • Miwarre schrieb:

    angriff schrieb:

    If I start a timer then kill it. I know from another thread that you cannot restart it if I kill it. Therefore, it is best to pause it.
    It depends: re-creating a new timer when you need it (after having killed a previous timer) may be fine too. May even be better if you need an initial delay.

    angriff schrieb:

    The question is if I kill it and I have an action to restart the event method can I use the timer all over again? I would think you could but knowing may save me hours of testing. Thanks
    You gave the answer yourself already: "you cannot restart it if I kill it" (aside: I do not understand what you mean by "I have an action to restart the event method").
    ok so I start the timer.. I pause the timer.. if I start the timer again does it start all over or begin with the last tick? Do I have to keep track of the ticks to get a single timed event that can pause in the middle?

    if I kill the timer to clean things up after some event .. can I reinitialize the timer with a event method or is it dead forever.
  • ok from the API doc stuff

    Pause pauses this timer. This has no effect if the timer is currently not active. You can always resume by calling start()

    Now i just want to know if I can kill a timer and not have to reload the plugin? If I have it running and dont need it for the next few hours until another event should I kill it then let the event re-initialize it with the same name or do I need a new name?


    so let me simplify is there any way to reset the timer to 0 for another start in the future without killing it? Or do you just have to let it expire.. which is a problem if you have executed code by the timer that you may or may not want to execute.

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von angriff ()

  • angriff schrieb:

    ok so I start the timer.. I pause the timer.. if I start the timer again does it start all over or begin with the last tick?
    This is a good question and the documentation is not completely clear about it; I am tempted to read it that start() after a pause() starts the timer from the beginning, resetting the initial delay and the repetitions, but you may want to test it, for instance using an initial delay noticeably different from the interval: if this initial delay occurs on re-start(), then it resets the timer to initial conditions.

    angriff schrieb:

    if I kill the timer to clean things up after some event .. can I reinitialize the timer with a event method or is it dead forever.
    If you kill a timer, that timer is gone; but of course you can create another! What let you think that you cannot create as many timers as you need / want (memory permitting of course) at any moment you need it?

    angriff schrieb:

    ok from the API doc stuff
    Good! The API documentation is your friend, for all these matters!

    angriff schrieb:


    Now i just want to know if I can kill a timer and not have to reload the plugin? If I have it running and dont need it for the next few hours until another event should I kill it then let the event re-initialize it with the same name or do I need a new name?


    so let me simplify is there any way to reset the timer to 0 for another start in the future without killing it? Or do you just have to let it expire.. which is a problem if you have executed code by the timer that you may or may not want to execute.
    You are making it much more complex than it is:
    - when you need a timer, create it;
    - when you have done your timed task and no longer need that timer, kill it.

    This is all!
    __________
    My plug-ins: Planks 'n Beams, GPS, UPS, Weather control, Plugin Central, RWGui (GUI back-end), Bank (Money back end)
  • Miwarre schrieb:

    This is a good question and the documentation is not completely clear about it; I am tempted to read it that start() after a pause() starts the timer from the beginning, resetting the initial delay and the repetitions, but you may want to test it, for instance using an initial delay noticeably different from the interval: if this initial delay occurs on re-start(), then it resets the timer to initial conditions.
    I too think this is the case after some testing, though I did not thoroughly test with many test cases so can't be 100% certain.

    A small note, even if you have a timer called timer1 running there is nothing preventing you from creating a second timer called timer1 with different settings and runnable task and the two timers will not have any problem coexisting with one another ;) The beauty of java :D
    Admin on Artisan's Realm
    Rising World Projects:
    Blueprint Texture Editor
    MailingSystem
    ServerTools
    Portals
  • Thanks for the replies and testing. Since the timer restarts after a pause (pause is a stop with a restart not a vernacular pause) I cannot do what I wanted to do with the timer I will have to count the ticks and keep track of them to make the decision to execute the code then.

    Total time with the timer running in game time is important to the decision but the duration of real time is not. I will need to pause the counting then restart counting at the last known count. Again thanks for being a sounding board.
  • Minotorious schrieb:

    What exactly are you trying to do, from what you just said it sounds to me like you don't need a timer at all and could do it with just a count variable increasing in value as it goes :/ But without exact infomation I can't know tbh
    Yeah, basically it is just a countdown that is stop and started. Seeing the pause feature seemed it would have been ideal if the timer itself could be stopped restarted at the same tick mark and then execute the code. But I see the word pause is actually a stop/finished.

    So that brings up another thought. If I pause a timer it should not execute the code unless if completes the entire count correct? I have some funny timing things going on in my routine right now that I am trying to sort out.

    going to have to buy Java for dummies :/ :S
  • angriff schrieb:

    going to have to buy Java for dummies
    I have that book :D hahaha never read it but I have it somewhere in the basement XD

    angriff schrieb:

    So that brings up another thought. If I pause a timer it should not execute the code unless if completes the entire count correct? I have some funny timing things going on in my routine right now that I am trying to sort out.
    Well it depends how you set it up but if the timer is paused before the trigger time interval has been reached then yes the runnable task will not be executed
    Admin on Artisan's Realm
    Rising World Projects:
    Blueprint Texture Editor
    MailingSystem
    ServerTools
    Portals
  • Minotorious schrieb:

    if your Timer is set to execute every 1 second then yes you will only get 0 from the .getTick method as when it reaches 1 the Runnable is executed.

    The Tick is a value from 0 to "float interval" set in the Timer.
    no new Timer (240F,0F,0,()-> {. I start it and the want to report the current state of the timer.. maybe use it in future for notifications of impending events.
  • if you initialise your timer like this, (240F,0F,0,()-> { then the getTick method should return all values between 0 and 240

    Edit: 239.999999 (many nines :D) in fact as at 240 the Runnable is executed and your timer stop as the repetitions are set to 0 (i.e. execute only once).
    Admin on Artisan's Realm
    Rising World Projects:
    Blueprint Texture Editor
    MailingSystem
    ServerTools
    Portals
  • Minotorious schrieb:

    if you initialise your timer like this, (240F,0F,0,()-> { then the getTick method should return all values between 0 and 240

    Edit: 239.999999 (many nines :D) in fact as at 240 the Runnable is executed and your timer stop as the repetitions are set to 0 (i.e. execute only once).
    Ya I am not having trouble with the runnable executing.. It is I cannot seem to get the timer to tell me that it has 240 left. So I suppose I need to do an algebraic to get that. But is always seems to say 0. ?(
  • how exactly are you getting the Tick? something like float tick = myTimer.getTick(); should give you the right value.

    I personally am using it a bit differently to get an int value i.e. int tick = (int) myTimer.getTick();

    But I think you shoud only call the getTick method from outside the timer's Runnable task, else I think it always returns 0
    Admin on Artisan's Realm
    Rising World Projects:
    Blueprint Texture Editor
    MailingSystem
    ServerTools
    Portals
  • angriff schrieb:

    When a timer finishes and executes it action does the program logic continue from the last bracket?
    If you pause a timer while the task is still active, the current task will still be completed, but no more tasks will be executed until you restart the timer. E.g. if your task runnable looks like this:

    Java-Quellcode

    1. System.out.println("before");
    2. timer.pause();
    3. System.out.println("after");

    ...the output will be:

    Quellcode

    1. before
    2. after

    Even if you kill the timer, the currently active task will still be completed ;) Or did you mean something else?
  • Benutzer online 1

    1 Besucher