1 Reply Latest reply on Mar 2, 2013 4:56 AM by Ned Murphy

    Using a timer as a score system

    Kilzar

      Hey Actionscripters,

       

      I've recently started using Flash (Action Script 2.0). For one of the projects at school they are getting us to essentially make our own puzzle games from scratch.

       

      On the frame at which the puzzle sits I have a big button that says start. Clicking this button makes the first puzzle piece appear on stage and when you place it within set coordinate the next puzzle piece is moved on stage and so on until piece 9; the final piece were it goes to the next frame - The score frame/winning frame?

       

      Pretty simple, but another function the start button has is it starts a timer (timer is a var name set to a dynTextbox). Essentially I want it so that when the final piece of the puzzle is placed the timer is stopped and the time that it stopped on is saved and put on the score tab, plus stored in a var or something so that I can use it later.

       

      I made the timer, but when I sorta figured out how to make it trace the last number in the timer I broke it and have hit a wall with no idea what to do.

       

      Here are my codes:

       

      START button -

      Code:

      on (release){

                timer = 0; //Sets the variable to 0

       

                countup = function(enabled:Boolean){ //Creating the countup function

                          if (enabled == true) {

                                    timer += 1; //timer function

                          } else {

                                    timer = timer;

                          }

                          _root.btn_llamastart.enabled = false;

                }

       

      }

      on (release){

                countupInterval = setInterval(countup,1000); //Set the counting internval to X

       

                setProperty(_root.llama_p1, _x, "640.80");

                setProperty(_root.llama_p1, _y, "164.30");

      }

       

       

       

       

      Piece 9 (last piece) -

      Code:

      on (press) { //On event 'press'

                startDrag(this); //Starts draging object }

       

      }

       

       

      on (release) {

                stopDrag(); //Stops dragging

          if ((this._x >0) && (this._x < 30) && (this._y >260) && (this._y <360)) {  // if puzzle pieces is within these set boundaries

                    setProperty(this, _x,"14.60"); //Set objects coordinates to set ones

                    setProperty(this, _y,"314.25"); //Set objects coordinates to set ones

                          gotoAndStop(4);

                          var totalTime:Number = _root.timer;

                          trace(totalTime);

                          countup(false);

          }

      }

       

       

       

       

      If someone could help me do what I want to achieve, that would be awesome.

       

       

      Cheers! 

       

       

      edit : I want to use the last time to be put on a leader board kind of thing as well. Less amount of time taken to most.

        • 1. Re: Using a timer as a score system
          Ned Murphy Adobe Community Professional & MVP

          What broke?  You should learn how to use the trace function to troubleshoot your code.  YOu can use it to track what happens to different values during the processing to home in on where the problem lies.

           

          It looks likeyou are using Actionscript 1 more than Actionscript 2, setProperty is AS1 coding and is unnecessarily complicating things for you. 

           

          You should get your code off of the objects and place it in the timeline, using instance names to target the different object you place it on now.

          1 person found this helpful