3 Replies Latest reply on Dec 2, 2010 3:13 AM by DazFaz

    Syntax problem for a conditional statement

    CoolBlueParrot

      My son is doing a self-study course and is currently haviong a problem with the syntax of a condtional statement in Actionscript 2

       

      The folllowing code,

       

      if (colour="red")
      {gotoAndPlay("BadEnd_red")}

      else if (colour="blue")
            { gotoAndPlay("BadEnd_blue")}

            else   //colour ="green"
           { gotoAndPlay("BadEnd_green")}

      always goes to the frame, "BadEnd_red" regardless of the value of the variable colour.  In fact, the first line is treated as an assignment statement.  I changed the code in an earlier frame to set the value of colour to "purple" and it still went to the frame, "BadEnd_red" and set colour to "red".

       

      Can anyone see the error or possible error as we seem to have exhausted all possibilities.

        • 1. Re: Syntax problem for a conditional statement
          DazFaz Level 1

          Within the "if" and "else" conditions you are declaring the value of "colour" rather than evaluating it.

           

          What you have is:

          if (colour="red")
          {gotoAndPlay("BadEnd_red")}

          else if (colour="blue")
                { gotoAndPlay("BadEnd_blue")}

                else   //colour ="green"
               { gotoAndPlay("BadEnd_green")}

           

          What it should be is:

          if (colour=="red")
          {gotoAndPlay("BadEnd_red")}

          else if (colour=="blue")
                { gotoAndPlay("BadEnd_blue")}

                else   //colour ="green"
               { gotoAndPlay("BadEnd_green")}

           

          This is a very quick reply and this was the first problem I saw.

          • 2. Re: Syntax problem for a conditional statement
            CoolBlueParrot Level 1

            Dear DazFaz,

             

            Thank you very much for your reply. The script now works as it was intended.

            It's almost midnight in Australia and we can go to bed now knowing that the

            problem is now solved.  I was a programmer ion the 80's & 90's and I find

            that the level of detail given in the online instruction manual on

            Actionscript is very poor.  We looked at a number of tutorials and although

            they give examples, they aren't general enough for one to work out the

            correct syntax.

            Once again, thank you for your help.

             

            regards,

            CoolBlueParrot

            • 3. Re: Syntax problem for a conditional statement
              DazFaz Level 1

              You are very weclome.