reset timer

Hello, yes I am asking another question, I have a timer counting down from ten to zero but I'm not sure how I can make it reset to 10 and count down again straight away without resetting the scene.

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    If you can show the rules you are using to create the timer someone can probably help easier.

  • jessica.michaeljessica.michael Member, PRO Posts: 27


    and I also have a game attribute for timer that is an integer and is set at 10

  • Two.ETwo.E Member Posts: 599
    edited November 2018

    Mis-read actual problem. @tatiang has solution.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2018

  • Two.ETwo.E Member Posts: 599

    @tatiang said:

    Am I missing something? There is no point in reseting it to 10 if the actor is being destroyed after 10 seconds anyway?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2018

    @Two.E Hmm, good point. But my understanding was that @jessica.michael wanted a timer that counted down from 10 and then immediately reset back to 10 in order to continue counting down.

    So maybe remove the destroy actor behavior altogether...

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited November 2018

    And for anyone wondering, as I did, why mod(game.Timer-1,11) cycles through the values 10, 9, 8, ... 2, 1, 0, 10, 9, 8, ... instead of going negative when game.Timer is zero...

    Here's a definition of the mod function (aka %) from the Lua Reference Manual:

    a % b == a - math.floor(a/b) * b

    So when game.Timer is zero, we get this:

    -1 % 11 == -1 -floor(-1/11) * 11
                 == -1 -(-1 * 11)
                 == -1 +11
                 == 10

    [My description of mod() as "the remainder from a division problem" wasn't entirely accurate because -1 divided by 11 = 0 with a remainder of -1 whereas the correct answer is 10 according to the equation above.]

    But @Socks probably knew all that ;)

Sign In or Register to comment.