Skip navigation
Currently Being Moderated

Small problem

Nov 4, 2011 8:32 PM

The second equality is when the player did not input anything. How can I translate it in as3 ?  Thank you for helping.

 

 

if (Number(outputexte.text) !=1111 || Number(outputexte.text)==????)

 
Replies
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 5, 2011 4:39 AM   in reply to Samsimms

    If you are looking for a value of not-valid Number, there's a method for that: isNaN();

    if (Number(outputexte.text) !=1111 || isNaN(Number(outputexte.text)))

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 5, 2011 4:39 AM   in reply to Samsimms

    You can also check the length proprtyu of the textfield to determine if nothing has been entered...

     

    if (outputexte.length  == 0 || Number(outputexte.text) !=1111 )...

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 5, 2011 6:31 AM   in reply to Samsimms

    If you trace the following when the textfield is empty you'll see why Peter's offering does not work...

     

    trace(Number(outputexte.text));

     

    It outputs a 0, which is a number, so the isNaN function...

     

    trace(isNaN(Number(outputexte.text)));

     

    will output a false result.

     

    You should learn to use the trace() function to troubleshoot and investigate things, it is one of the best tools around for troubleshooting code that doesn't work.

     

    Peter's offering will work well if you do not want to allow anything but numbers to be entered, but you can also just restrict the characters of the textfield to be numeric values to get around that.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 6:47 AM   in reply to Samsimms

    Probably you don't need to check the length since you can just do

    if(outputexte.text != "1111")
    

    or

    if(parseInt(outputexte.text) != 1111)
    

    --

    Kenneth Kawamoto

    http://www.materiaprima.co.uk/

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 2:37 AM   in reply to Samsimms

    I'm not saying the code you have is wrong but logically since your second part of the conditions covers the first part of the conditions, your first part of the conditions is superfluous.

     

    You have

    (if the plate is empty) or (if what is on the plate is not banana)
    

    If there's nothing on the plate it's not banana anyway, so that you can just use...

    if what is on the plate is not banana
    

    ...to cover the situation when the plate is empty. Or better still, you could just use...

    if banana is on the plate
    

     

    So your code can just be

    if(outputexte.text == "1111")
    

    --

    Kenneth Kawamoto

    http://www.materiaprima.co.uk/

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points