A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: !=true == false? :)

  1. #1
    Senior Member
    Join Date
    Jan 2009
    Posts
    208

    !=true == false? :)

    maybe a stupid question, but i will still ask :P

    if i have a boolean and if i say if (something != true), is this the same as saying if (something == false) ?

    at first i thought yes, but i am not so sure anymore
    Last edited by regbolD; 01-18-2009 at 05:59 PM.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Conditionals will break everything into boolean values so:


    PHP Code:
    //  these are all true statements
    true == true
    false 
    == false
    true 
    != false

    //  these are all false statements
    true == false
    true 
    != true
    false 
    != false 
    So yes - saying something "is not True" is the same as saying it "is false"

  3. #3
    Intermediate Game Dev pseudobot's Avatar
    Join Date
    May 2008
    Location
    New Zealand
    Posts
    561
    Not exactly. Here's an example:

    PHP Code:
    varA "true"
    varB "b"

    if (varA == true) {
    trace(varA); //returns "true"
    }
    if (
    varB != true) {
    trace(varB); //returns "b", becacuse even though it is not true and not false,         
                     //the statement is still correct, because "b" IS NOT  true

    Needs an update...

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Those are both strings - which get evaluated to 'true' if they have ANY value in them - Flash doesn't care what that value is...


    PHP Code:
    var s:String "false";
    var 
    b:Boolean Boolean(s);
    trace(sb);    //  false  true 

  5. #5
    Senior Member
    Join Date
    Jan 2009
    Posts
    208
    so if i dont even declare something as boolean and just say in my code somewhere that: something = true;

    an then later ask:

    if (something != true)

    is the same as saying?

    if (something == false)


    so basically does this mean that whenever i just mention true or false boolean is implied?
    Last edited by regbolD; 01-19-2009 at 08:49 AM.

  6. #6
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Whenever you use if (or any other conditional operator) everything will get cast to Boolean - so in your example (assuming 'something' is in the same scope as your if statement) that should work fine. You can even do away with the comparison altogether:

    if(something){}
    if(!something){}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center