Thread: How do you make a timer cycle without putting it in process..

Results 1 to 7 of 7
  1. #1 How do you make a timer cycle without putting it in process.. 
    Registered Member Dezzan's Avatar
    Join Date
    Oct 2009
    Age
    27
    Posts
    409
    Thanks given
    2
    Thanks received
    6
    Rep Power
    30
    I don't know how to call a timer to make it constantly count down without throwing it in process.

    Basically.. I don't know how to call this every second or half second...

    Code:
    	if (timer < 1) {
    		timer = ##;
    	} else if (timer > 0) {
    		timer--;
    	}
    Reply With Quote  
     

  2. #2  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    886
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Quote Originally Posted by Sabre Rush View Post
    I don't know how to call a timer to make it constantly count down without throwing it in process.

    Basically.. I don't know how to call this every second or half second...

    Code:
    	if (timer < 1) {
    		timer = ##;
    	} else if (timer > 0) {
    		timer--;
    	}
    It depends on what you're actually looking for. If you're looking to make it so it updates on a separate thread, you'd just need to create a separate thread that will sleep for 500-600ms, then loop through again (Which I doubt you want to do).

    If, however, you just want to do something like update the timers in a different method, just do something like this.

    Code:
    private void updateTimers() {
        /* Updating Code Here */
    }
    Then, in process, call the method somewhere.
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Mar 2009
    Age
    28
    Posts
    1,008
    Thanks given
    32
    Thanks received
    7
    Rep Power
    111
    Code:
    updateTimers();
    C+P plz
    Reply With Quote  
     

  4. #4  
    Registered Member Dezzan's Avatar
    Join Date
    Oct 2009
    Age
    27
    Posts
    409
    Thanks given
    2
    Thanks received
    6
    Rep Power
    30
    Quote Originally Posted by i gf i View Post
    Code:
    updateTimers();
    C+P plz
    And what happens if we don't have that method
    Reply With Quote  
     

  5. #5  
    Registered Member Dezzan's Avatar
    Join Date
    Oct 2009
    Age
    27
    Posts
    409
    Thanks given
    2
    Thanks received
    6
    Rep Power
    30
    Quote Originally Posted by PSNB View Post
    It depends on what you're actually looking for. If you're looking to make it so it updates on a separate thread, you'd just need to create a separate thread that will sleep for 500-600ms, then loop through again (Which I doubt you want to do).

    If, however, you just want to do something like update the timers in a different method, just do something like this.

    Code:
    private void updateTimers() {
        /* Updating Code Here */
    }
    Then, in process, call the method somewhere.
    So then I guess there is no way to make timers count down by the second or half second without throwing it in process >.>
    Reply With Quote  
     

  6. #6  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    886
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Quote Originally Posted by Sabre Rush View Post
    So then I guess there is no way to make timers count down by the second or half second without throwing it in process >.>
    I said you could create a new Thread that would run through and update them all alongside the update thread, but that may cause some concurrency issues.
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Jul 2008
    Age
    26
    Posts
    5,826
    Thanks given
    1,301
    Thanks received
    197
    Rep Power
    0
    Code:
    long someTimer;
    
    
    public void doSomething() {
      if(System.currentTimeMillis() - simeTimer > (time, in ms)) {
        doAction();
        someTimer = System.currentTimeMillis();
      }
    }
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •