9 Replies Latest reply on Aug 3, 2013 7:32 PM by Sean_Wilson

    Countdown Timer

    DirBuddy12

      I have been told by my Lectuer that I have to have a countdown timer within the game I am making but that I am not allowed to use the one within director.

       

      I have no clue where to start with this could someone please give me some advice on how to create a simple timer or where to find the best information online about it.

       

      Also I have thought about either adding time or freezing time as part of bonus from the game, which would be easier to implement?

       

      Any help is greatly appreciated Thank You

        • 1. Re: Countdown Timer
          Sean_Wilson Adobe Community Professional

          Did you search within this, and the Lingo, forum for previous responses to similar questions?

          • 2. Re: Countdown Timer
            DirBuddy12 Level 1

            Yeah I have but I haven't found one that is just a countdown timer they all have more added to the code and I don't understand what parts are to do with the timer and which aren't.

             

            Though I attempted to create a timer using this code it presents no errors but it doesn't do anything.

             

            global counter

            on startmovie

             

              counter = 90

              set the value of sprite(36) to counter

             

            end

             

             

            on prepareframe

             

              repeat while counter <> 0

                set the value of sprite(36) to counter

               

              end repeat

             

                if counter = 0 then

                go to frame 539

             

             

                end if

            end

            • 3. Re: Countdown Timer
              MECS Level 1

              I don't see where you increment your counter.  

               

              Try changing this line     "set the value of sprite(36) to counter"

               

              to this      "set the value of sprite(36) to counter - 1"

               

              Dewey

              • 4. Re: Countdown Timer
                DirBuddy12 Level 1

                Ok I guess I understand now that that didn't make much sense but still the counter doesnt appear within the field I want it too though.

                 

                Is there another way to set the value?

                • 5. Re: Countdown Timer
                  Sean_Wilson Adobe Community Professional

                  Try instead setting the text of the member of sprite 36 to the string representation of some integer. You might also want to subtract 1 every frame instead of doing it all at once the first time prepareFrame is called:

                  global counter
                  
                  on startmovie
                    counter = 90
                    sprite(36).member.text = string(counter)
                  end
                  
                  on prepareframe
                    counter  = counter - 1
                    sprite(36).member.text = string(counter)
                  
                    if counter = 0 then
                      go to frame 539
                    end if 
                  end
                  

                  The above alterations might help, but you'd be better to place the prepareFrame handler in a score script attached to your counter sprite, or in the frameScript channel, instead of in a #movie script (where it appears to be now)

                  1 person found this helpful
                  • 6. Re: Countdown Timer
                    DirBuddy12 Level 1

                    Thanks that makes more sense now.

                     

                    I don't understand what you mean by a score script I assumed you could only write scripts in the main script window?

                    • 7. Re: Countdown Timer
                      Sean_Wilson Adobe Community Professional

                      You should read the documentation to understand the difference between movie, score (behavior), and parent scripts.

                      • 8. Re: Countdown Timer
                        DirBuddy12 Level 1

                        I have changed the script type from behaviour to a parent script and I have also changed the script as much as I understand the parent script.

                         

                         

                        property counter

                         

                        on new me, aCounter

                        counter = 90

                        sprite(36).member.text = string(counter)

                        end

                         

                         

                        on moveSprite me

                          counter  = counter - 1

                          sprite(36).member.text = string(counter)

                         

                         

                          if counter = 0 then

                            go to frame 539

                          end if

                        end

                         

                         

                        I have probably not understood the parent script, sorry if this is confusing.

                        • 9. Re: Countdown Timer
                          Sean_Wilson Adobe Community Professional

                          I have no idea why you did what you say you did (making a parent script).

                           

                          I'm getting frustrated doing your work for you. I have tried to suggest where to go to help yourself but it doesn't seem to be working. Short of my doing your homework for you, how do you see your learning progressing from here?

                           

                          Step back and ask or answer some basic questions: you want to create a "countdown timer", and it appears you want it to count down from 90 to 0 - are my assumptions to date correct? Assuming they are: when do you want to start this timer and when do you want it to stop? Why are you counting down in the first place? I can see you want to jump to a frame when done (frame 539 - tip: it's better to name frames than to use a number) but are you ever going to want to pause your timer? How often do you want to decrement the timer - once a second or every time a frame is played in your Director file?

                           

                          Ignore what you've done already and attach the following as a behavior/score script to sprite number 36, or whichever sprite is serving as the timer display:

                          property spriteNum
                          property myMember
                          property myCounter
                          property myTimeout
                          
                          on beginSprite me
                            myMember = sprite(spriteNum).member
                            myCounter = 90
                            myMember.text = string(myCounter)
                            myTimeout = timeout().new("countdown", 1000, #mCountDown, me)
                          end
                          
                          on endSprite me
                            if objectP(myTimeout) then
                              myTimeout.forget()
                              myTimeout = VOID
                            end if
                          end
                          
                          on mCountdown me
                            myCounter = myCounter - 1
                            myMember.text = string(myCounter)
                            if myCounter = 0 then
                              me.endSprite()
                              go to frame 539
                            end if
                          end
                          

                           

                           

                          Hopefully you have explored enough to grasp what the above does, or can ask questions if you need to (after first consulting the Help file/s)