Announcement

Collapse
No announcement yet.

If, Else and Else if.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    If, Else and Else if.

    Okay I keep getting these mixed up.

    If X is red=red

    If x is red ,else is blue= blue comes before red

    If x is red, if else is blue= purple

    Is it something like that?

    #2
    ... what? I don't understand.

    This is pretty much the basic knowledge. Do yourself a favor and read the following page (and subpages):
    http://udn.epicgames.com/Three/Unrea...Reference.html

    Comment


      #3
      I did read it, it did not help much.

      I need it paraphrazed in slightly easier to understand trems.

      This is what I think it means

      If executes a bracketed code block.

      Else overrides the above IF code block.

      Else If dose both code blocks.

      I know I have something mixed up I just dunno which.

      Comment


        #4
        http://udn.epicgames.com/Three/Unrea...tructures.html

        Comment


          #5
          Read that awhile ago and still only vaguely get it.
          If is a 1 you get 1
          Else If is 2 you get 2 instead of a 1
          Else is a 3 you get a 3 instead of a 1 or 2

          Am I even close? :P(yes I can be easily confused ><)

          Comment


            #6
            UnrealScript is executaed line by line.

            Code:
            if (CONDITION1) 
               EXPRESSION1;
            elseif (CONDITION2) 
               EXPRESSION2;
            else
               EXPRESSION3;
            EXPRESSION1 will be executed when-if CONDITION1 is evaluated to true.
            EXPRESSION2 will be executed when-if CONDITION2 is evaluated to true but only if CONDITION1 is evaluated to false.
            EXPRESSION3 will be executed when CONDITION1 and CONDITION2 are evaluated to false.

            The evaluation of boolean variable is pretty obvious. If the boolean variable is true, the condition is evaluated to true (vice versa; false => false). A boolean variable can be negated by the operator ! (exclamation mark). If the boolean value is true, the negated boolean value would be false.
            Code:
            if (bVariable1) 
               EXPRESSION1;
            elseif (!bVariable2) // the if condition will be true if bVariable2 is false
               EXPRESSION2;
            else
               EXPRESSION3;
            Conditions are boolean expressions. A comparison is evaluated as a boolean expression. If you compare 2 values, it will be evaluated to true if these values are the same.
            Code:
            if (intVariable1 == 0) 
               EXPRESSION1;
            elseif (intVariable1 > 0)
               EXPRESSION2;
            else
               EXPRESSION3;
            In this case EXPRESSION3 will be executed if intVariable is lower than 0 (and not equal).

            A expression can be a variable assignment or a function call.
            Code:
            // some expressions
            GetIntOut(intVariable);
            SetInt(intVariable);
            intVariable = GetInt();
            
            ValidateInt();
            
            intVariable++;
            intVariable += 1;
            intVariable = 0;
            intVariable = intVariable + 1;
            intVariable = Min(intVariable, 10);
            If you got a function which returns a value, these can be used for a condition as well as these are evaluated.
            Code:
            function bool IsLowerZero();
            function int GetInt();
            
            if (IsLowerZero(intVariable)) 
               EXPRESSION1;
            elseif (GetInt() > 0)
               EXPRESSION2;
            else
               EXPRESSION3;

            Comment


              #7
              That makes things much clearer! Thank you!

              Comment


                #8
                http://wiki.beyondunreal.com/If etc.

                Comment


                  #9
                  Every little bit helps, thank you!

                  Comment

                  Working...
                  X