2 Replies Latest reply on Apr 15, 2010 7:22 AM by NOCK2k8

    Working out a score from a timer.

    NOCK2k8

      Here we go,

       

      I have a maze that a man walks around with a countdown timer showing on the screen that counts down from 5:00 down to 0:00.

       

      On completion of the maze, the play head skips to a different frame and I want to work out a score based on the time that it took for the man to complete the maze.

       

      I have pasted the code that I have got so far, I know it will need quite a bit of work:

       

      --global minscore, savedTime

       

      -- behaviour script attched to a text sprite
      on beginSprite me
        sprite(me.spriteNum).member.text = "5:00"
        startTimer()
      end beginSprite

       

      on enterFrame me
        tSecElapsed = (the timer)/60
        if tSecElapsed < 300 then
          tTime = 300 - tSecElapsed
          tSec = tTime mod 60
          if tSec < 10 then
            tSec = "0" & tSec
            --if sprite("man").intersects(sprite("finish")) then savedTime=tSec
          end if   
          tMin = tTime/60
          sprite(me.spriteNum).member.text = tMin & ":" & tSec
          -- if tMin = "5" then minscore = "5000"
          --  if tMin = "4" then minscore = "4000"
          --  if tMin = "3" then minscore = "3000"
          -- if tMin = "2" then minscore = "2000"
          -- if tMin = "1" then minscore = "1000"
          -- if tMin = "0" then minscore = "0"
          -- end if
        else
          sprite(me.spriteNum).member.text = "0:00"
          go to "EndScreenLevel1Lose"
        end if
      end enterFrame

       

      The commented out lines (apart from the second one down from the top), are lines that I have attempted to add in to deal with scoring, the other lines are used for the timer.

      At the moment, when the play head skips to the new screen, the timer starts again which is obviously an issue.  But I also need to know how a) work out the score and b) display it if the maze has been completed.

       

      I have looked around for a tutorial on this as it must be a pretty common thing but I've had no luck so far.

       

      Any help greatly appreciated.

       

      File can be found here.

       

      Thanks in advance.

        • 1. Re: Working out a score from a timer.
          NOCK2k8 Level 1

          Anyone able to help with this at all?

           

          I hope so,  thanks in advance!

          • 2. Re: Working out a score from a timer.
            NOCK2k8 Level 1

            I managed to work this out.

             

            Here is how I did it:

             

             

            global tMin, tSec

             

            -- behaviour script attched to a text sprite
            on beginSprite me
              member("Level1Score").text = string(tMin * 1000 + (tSec * 16))   
            end beginSprite

             


            on enterFrame me
             
              tSecElapsed = (the timer)/60
              if tSecElapsed < 300 then
                tTime = 300 - tSecElapsed
                tSec = tTime mod 60
                if tSec < 10 then
                  tSec = "0" & tSec
                end if   
                tMin = tTime/60
                sprite(me.spriteNum).member.text = tMin & ":" & tSec
               
                member("Level1Score").text = string(tMin * 1000 + (tSec * 16)) 
               
              end if
            end enterFrame

             

             

             

            Hope this helps others who have the same problem.