Using the game clock for timers- Anyone have a tutorial or video?

design219design219 Member Posts: 2,273
edited November -1 in Working with GS (Mac)
I am working on a new game and starting to use a lot of timers. I've seen posts about using the game clock instead of timers for better efficiency, but as a non programing guy, I'm not getting how to put this into action.

Anybody have/know of a video or tutorial that could help?

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Create a new attribute called something like 'capturedTime'.
    Create a new attribute called something like 'delay'. Set it to whatever you want.

    It works like this:

    Change Attribute: self.capturedTime To: game.Time

    Rule
    When all conditions are valid:
    game.Time > self.capturedTime + self.delay
    -----[do something]
  • design219design219 Member Posts: 2,273
    Should 'capturedTime' and 'delay' be an integer or real?

    Sorry for the nooby questions.

    And Thanks!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    They can either. Depends on how much precision you need. If you need a delay of 3.5 seconds, use real for the delay.

    For capturedtime, i would use a real.
  • design219design219 Member Posts: 2,273
    Whoa, sweet! This works like a charm. And I also understand the concept now. I hope this does help with processor resources.

    Thanks!
  • design219design219 Member Posts: 2,273
    *edit*
    Nevermind, I got it.

    *Another timing need...

    *I want to make something happen every 16 seconds. Any suggestions on the most efficient way to do that with the game clock?
  • eaguirreeaguirre Member Posts: 89
    Just set the delay to 16 secs and copy this :

    Change Attribute: self.capturedTime To: game.Time

    Inside the Rule
    When all conditions are valid:
    game.Time > self.capturedTime + self.delay

    -----[do something]
    -----(here)Change Attribute: self.capturedTime To: game.Time
  • design219design219 Member Posts: 2,273
    Yes, I think I've got it. Thanks all!
Sign In or Register to comment.