GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

design219design219 Posts: 2,273Member
edited 6:57AM 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 Posts: 3,206Member
    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 Posts: 2,273Member
    Should 'capturedTime' and 'delay' be an integer or real?

    Sorry for the nooby questions.

    And Thanks!
  • firemaplegamesfiremaplegames Posts: 3,206Member
    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 Posts: 2,273Member
    Whoa, sweet! This works like a charm. And I also understand the concept now. I hope this does help with processor resources.

    Thanks!
  • design219design219 Posts: 2,273Member
    *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 Posts: 89Member
    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 Posts: 2,273Member
    Yes, I think I've got it. Thanks all!
This discussion has been closed.