3 Replies Latest reply on Feb 7, 2010 5:30 AM by Ned Murphy

    Coding Help! (Beginner)

    IxEatxPie
      Im trying to make a simple program (im a beginner)

      The user inputs a number between 1-10 into a box with the variable x

      They click a roll button named button1

      The number is always between 1-10, and is shown in a dynamic
      text box with the variable die

      There is also a dynamic text box, with the variable y, that displays Numbers match, or numbers dont match, depending on if they do or not (the roll and the one the user inputs)

      This is my code:
      stop();

      button1.onRelease = function(){
      die = Math.floor(Math.random() * 10) + 1;

      if (die == x){
      y = "Numbers match!";
      } else {
      y = "Numbers don't match!";
      }
      }

      My problem is in the line if (die == x){
      When i replace x with a number it works fine! But with the variable x in there it does not, do I have to turn the variable x into a number somehow? Remember x is the value that the user inputs into the input text box
        • 1. Re: Coding Help! (Beginner)
          Ned Murphy Adobe Community Professional & MVP

          If you are using the var assignment/property of the textfield, I recommend avoiding it.  Assign the textfield an instance name (I use inputField below as an example) and use the text property of it in your evaluations...

           

          (die == Number(inputField.text)){

           

          Similarly, for the message field, I would take the same approach.  I recommend against using the var thingy because it has always been problematic (for me) to deal with.

           

          • 2. Re: Coding Help! (Beginner)
            IxEatxPie Level 1

            Thanks a bunch! The code and program worked, I guess the problem was that the variable wasnt considered a numerical value.

             

            Thanks!!!

            • 3. Re: Coding Help! (Beginner)
              Ned Murphy Adobe Community Professional & MVP

              You're welcome.  AS2 is lenient when it comes to interpretting what's in a textfield, but undependably so... maybe it's some cosmic event calendar or something that it checks against to decide whether on a given day it will treat the value of a textfield as a number or not when you use it different ways.  The best way to get reliable results is to use the text property and treat it like text.