#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Using a timer as a score system


    Hey DevShed'ers!

    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.
  2. #2
  3. Plays with fire
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    942
    Rep Power
    97
    I'm a bit rusty with AS2, but try this:

    Code:
    var timer:Number=0;
    var counter;
    
    
    myButton.onRelease=function() {
      setProperty(_root.llama_p1, _x, "640.80");
      setProperty(_root.llama_p1, _y, "164.30");
    
      myCounter=setInterval(countup,1000);
    }
    
    function countup() {
      timer++;
    }
    Be sure to clearInterval(myCounter) when the last piece is dropped.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence

IMN logo majestic logo threadwatch logo seochat tools logo