3 Replies Latest reply: Sep 25, 2012 9:10 AM by Ned Murphy RSS

    Score variable problem

    Gater

      Hi ,

      Having a problem with a basic scoring system

       

      I have the below on the first frame:

       

      stop();

      var score:Number = 0;

       

      with a dynamic text area with the variable score

       

      Then certain frames with:

      _root.score += 20;

       

      this all works fine

       

      The problem is when I want a mc to go to a certain frame depending on the final score, i have the below but not working, any suggestions would be welcomed

       

      stop();

      if (score==100) {

          options.gotoAndStop("100");

      }

      if (score==80) {

          options.gotoAndStop("80");

      }

      if (score==60) {

          options.gotoAndStop("60");

      }

      if (score==40) {

          options.gotoAndStop("40");

      }

      if (score==20) {

          options.gotoAndStop("20");

      }

      if (score==0) {

          options.gotoAndStop("0");

      }

        • 1. Re: Score variable problem
          Ned Murphy MVP

          First, if those are frame numbers in your goto lines, do not use quotes.  If they are frame labels, do not use numbers for frame labels.

           

          You should avoid using the var property of a textfield and just read the text property of the textfield.  So overall, using a variable, your code would switch the numbers with the strings, as in...

           

          if (score.text == "100") {

              options.gotoAndStop(100);

          }

          • 2. Re: Score variable problem
            Gater Community Member

            Thanks very much Ned, it was the numbers as frame lables that was the problem. Amended to the below and it now works fine.

             

            stop();

            score = score + "%";

             

            if (_root.score =="100%") {

            _root.options.gotoAndStop("hundred");

            }

             

            else if (_root.score =="80%") {

            _root.options.gotoAndStop("eighty");

            }

             

            else if (_root.score =="60%") {

            _root.options.gotoAndStop("sixty");

            }

             

            else if (_root.score =="40%") {

            _root.options.gotoAndStop("forty");

            }

             

            else if (_root.score =="20%") {

            _root.options.gotoAndStop("twenty");

            }

             

            else if (_root.score =="0%") {

            _root.options.gotoAndStop("zero");

            }

            • 3. Re: Score variable problem
              Ned Murphy MVP

              You're welcome