Need help with a countdown script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jorhajnes
    New Member
    • Jan 2008
    • 1

    #1

    Need help with a countdown script

    Hi there.

    Im very new to making games in flash, although I have used flash for quite some time now in web-based situations so I know my way around.
    Anyways, I thought it would be fun to try making some sort of game and I got stuck… :P I managed to get a clock counting down from 30 to 0 and then collect the score but I get in trouble when i try to make a button that restarts the procedure since i then get the doubled clock speed counting down, i fixed this by making two versions of the same thing one with -1 in time and one with -0 that would be used for restarting and it worked flawlessly, until now.
    I made a second game-style in the menu and then i need to have -1 in time there if someone wants to start there so back at square one… Is there anyway to reset the scripts for time when the score is collected so that when I start over I dont get the double script? my script for the countdown looks like this:

    setInterval(cou ntdown,1000); time = 30; function countdown() { time = time-1; if (time<=0) { gotoAndStop(“do ne”); } }

    It cant be that setInterval(cou ntdown,1000); gets doubled because then it would take twice as long time for each second to tick down and it goes faster so thats not the problem, and it can be the { time = time-1; that gets doubled either, then it would tick down 2 numbers for each second…? I really dont have any clue to why I get a faster countdown in the time when i restart…

    Here’s how it behaves:
    1st time: all normal
    2nd time: 30 normal 29,28 fast, 27 normal, 26,25 fast, 24 normal and so on
    3rd time: 30,29,28 fast 27 normal, 26,25,24 fast…
    And it just keeps increasing in speed for every time I restart…

    Any ideas?
Working...