Posted on by
NOTE: This tutorial is outdated and has been replaced by the Utilizing Time and Dates tutorial.

Posted by . Thanks for reading...

9 Responses to “Working with Time: Delays and Counting”

  1. Naomi

    Thank you for posting the tutorial. Regarding the iteration, I believe the default is 1 (not 0) — maybe a typo? Or do we need to add 1 now if we don’t want it to iterate infinitely…?

    Reply
  2. Jonathan Beebe

    Oops, nice catch! I updated the article to be accurate (1 as the default).

    And I also updated the article to use the phrase “anonymous function” instead of closure to prevent any confusion :-)

    Thanks for the feedback!

    Reply
  3. Mo

    Good timing Jon! I am working on collision and timer and this was perfect!

    Mo
    (LairdGames)

    Reply
  4. Mark

    Note that calculating elapsed time is more complex if you have to take account of pausing gameplay or the OS switching to another app!

    Reply
  5. Chris

    Very timely article (sorry for the pun). Cleared up a few problems I was having with regards passing parameters to functions from a timer.
    Many thanks :)

    Reply
  6. Nick

    This article came just in time. It was very timely and also save me some time. I also had a good time, while reading about it…this time. Maybe next time I’ll have a better time, but right now it’s the best time and the right time to read about time.

    Good times.

    That’s right, I went there. Great article,

    I really enjoyed the


    local function hello_world( arg1, arg2 )
    print( "Hello world!", arg1, arg2 )
    end

    timer.performWithDelay( 1000, function()
    hello_world( "first", "second" )
    end, 1 )

    I’m not cool enough yet to realize you could do that! I already have many uses for that :)

    Thanks again!

    ng

    Reply
  7. Mo

    Hello Jonathan.

    Sorry to steal some space from this thread but is there ANY chance to see a tutorial on in-app purchase (ios)? I have been reading about it all over the forum but only you can make something complex easy to understand. Obviously this “working with time” is a good example among others!

    Please, please, pretty please:)

    THANKS!

    Mo.
    (LairdGames)

    Reply
  8. Tadd

    I used a lot of this type of call in my game previously, but it ended up being so many it really bogged down the game and I couldn’t get them to cancel right. So I ended up making a variable to count for me …

    LIke …

    local timervar = 0

    function timevarincrease()
    timevar = timevar + 1
    // if something happens at a certain ‘time’
    if timevar >= 50
    timevar =0
    end
    end

    Runtime:addEventListener(“enterFrame”, timevarincrease)

    This worked better. I’m sure I did 1000 things wrong with dropping the time function but .. time will tel. HAH!

    Reply

Leave a Reply

  • (Will Not Be Published)