Another Timer techinical question

  • 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
    System.out.println("before");
    timer.pause();
    System.out.println("after");

    ...the output will be:

    Code
    before
    after

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

    Well that was good but, No it was not what I was asking. The routines in the timer always execute when the timer goes off. The question is about detecting a .isPaused. I have a routine that was detecting a paused timer in an if statement just fine but then I enhanced the routine which moved it up in the ladder and it seemed to never detect the paused timer out of the executable never executed. I finally put a toggle variable in and that appears to have remedied it.


    I was asking of the .isPaused detection of a routine is not a reliable IF routine trigger for one. Then if the timer is in .isPaused mode would code below it execute properly this could include turning the timer back on when another event was detected? Because the next time the event detection happened my routine would act if the timer was not paused.


    In any case I have it working good enough but I did not like using a detection boolean variable as it as problematic in the logic. But the reliable detection of .isActive verses .isPaused is the question. Are they reliable detection methods of what the timer is doing or can they be sometimes not detected? And if the timer is paused will the routine detect this and skip it the next time around as if it was not there?

  • I was asking of the .isPaused detection of a routine is not a reliable IF routine trigger for one. Then if the timer is in .isPaused mode would code below it execute properly this could include turning the timer back on when another event was detected? Because the next time the event detection happened my routine would act if the timer was not paused.

    yes ofc all further code can and is executed like nothing happened, you are in an Object Oriented Environment your methods can be called at any time by any other method and be executed even in parallel at the same exact second. Event calls are completely separate as well, if for example a PlayerChangePositionEvent and a PlayerHitEvent are called at the same time both events will be executed, the program will not wait for one code snippet to finish so that it can reach the second, if that was the case we wouldn't be in an Object Oriented Environment but a linear main function.



    Well that was good but, No it was not what I was asking. The routines in the timer always execute when the timer goes off. The question is about detecting a .isPaused. I have a routine that was detecting a paused timer in an if statement just fine but then I enhanced the routine which moved it up in the ladder and it seemed to never detect the paused timer out of the executable never executed. I finally put a toggle variable in and that appears to have remedied it.

    if the timer has started and has not finished but was paused the .isPaused method should detect it. Could you maybe provide a code snippet for us to see what you are trying to achieve?

  • Is the reverse true for pausing then restarting it? The .isActive to see that it is counting down is important. So the routine .isActive sees that it is running and continues to the next statement which .pause() it. The next time I go through the event it should see that it is .isPaused and that is where I was having trouble. The next time it would not jump the .isPaused routine and would execute the routine IF statement trying to detect it with IF (timer.isActive) blah blah. It was as if I did not start the timer but I put a output that said it was started at the correct line. I move the statements around in the logic and it worked better but not reliably until I put the toggle in. When checking for either the timer and the toggle it works. So I was wondering about the ability to toggle the timer off and on and detect it immediately.

  • ok I am confused ?( Why don't you do something as simple as this:


    Just make sure the Init method is definitely called before the check method else you might get an exception (probably null Exception) ;)

  • ok I am confused ?( Why don't you do something as simple as this:

    Just make sure the Init method is definitely called before the check method else you might get an exception (probably null Exception) ;)

    Well thanks for that but what I am doing is not that simple. The detection of the timer being active or paused by of the actions of another player someplace else on the map is important. With a bunch of other imbedded decisions in between. Anyway I have it working <knock on wood>. It is probably that the timer starts once or is not initialized because of a second event. Probably a start and restart of the routine caused the timers to stop in a branch not totally sure. The toggle solved the issue just had to do some extra statements and placement of the actions to make it reliable both in a fast or delayed response. You guys are indicating that it should follow through so seems a branch out a logical the culprit but I get bleary eyed looking at it.


    It is testing fine now. ||8|

  • Well thanks for that but what I am doing is not that simple. The detection of the timer being active or paused by of the actions of another player someplace else on the map is important. With a bunch of other imbedded decisions in between. Anyway I have it working <knock on wood>. It is probably that the timer starts once or is not initialized because of a second event. Probably a start and restart of the routine caused the timers to stop in a branch not totally sure. The toggle solved the issue just had to do some extra statements and placement of the actions to make it reliable both in a fast or delayed response. You guys are indicating that it should follow through so seems a branch out a logical the culprit but I get bleary eyed looking at it.

    well as I said if you don't provide code for me to see and fix I cannot help you any more than by providing simplified examples :/


    Glad it works for now at least :)

  • Not a problem Minos.. thanks for the confirmation. What I am doing is pretty ugly code and it would take a bit to explain why this pause vs this start if this pause is on .. so I am sure it is/was a sequencing error. It is working on my server now so I dont want to touch it. Thanks again.. you guys are/have been really helpful.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!