Author Topic: Script/Boolean test question ! vs. !=  (Read 351 times)

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« on: September 26, 2012, 07:54:41 pm »


               Can someone clairfy the correct use of ! vs. !=.in an if statement?

Say I have an area int...let's call it int iInt = 1.

Does this work:
1)  if (!GetLocalInt(oArea, iInt)    
Would this resolve to FALSE (since iInt =1) and therefore the commands inside the if statement would not get performed.  If iInt were 0/unset, would it resolve to TRUE and the commands in the if statement would get performened

Or, would I need to position it this way:

2)  if (GetLocalInt(oArea, iInt) != 1) 

Or, are they the same?  I was thinking they were the same thing, just the first example as a smidge quicker to process as it doesn't have to test for the value of the int, just whether it is TRUE (1 or some other number) or FALSE (0).  The second would be prefferable if iInt had multiple potential values that I'd be testing for (e.g. if iInt==2, do something else)

Can someone clarify?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #1 on: September 26, 2012, 08:01:41 pm »


               1) will be TRUE only when the value returned by GetLocalInt will be 0

2) will be TRUE always as long as the value isnt 1, but can be 2, -1 etc.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #2 on: September 26, 2012, 08:15:57 pm »


               Also:

GetLocalInt  returns 0 if the integer is not found on the object.  0 is the default value for integers.

Furthermore an aside
     GetLocalInt(oArea, iInt)
is not the same as
     GetLocalInt(oArea, "iInt")

if you have an integer on an area called iInt  you should use the later statement.
If on the otherhand iInt is a string, GetLocalInt(oArea, iInt) will look for an integer with a label that matches the string stored in iInt.

Yes thats a little pedantic, but it should be clarified to avoid confusion.
               
               

               


                     Modifié par henesua, 26 septembre 2012 - 07:16 .
                     
                  


            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #3 on: September 26, 2012, 08:20:22 pm »


               Many thanks.  That was my understanding.  And just to clarify, if a variable is unset, GetLocalInt will return 0, correct?
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #4 on: September 26, 2012, 08:35:50 pm »


               Yeah, forgot the quotes in my example.  Both should have read, GetLocalInt(oArea, "iInt")

Can you give an example of the second scenario, "If on the otherhand iInt is a string, GetLocalInt(oArea, iInt) will look for an integer with a label that matches the string stored in iInt."
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #5 on: September 26, 2012, 09:07:54 pm »


               (1) To clarify, yes GetLocalInt will return 0 if the integer is not set. This is however identical to not finding the integer on the object.

(2)
example code:
string sLabel  = "LOCAL_VARIABLE";
object oMod   = GetModule();
string iValue   = GetLocalInt(oMod, sLabel);

explanation:
GetLocalInt looks for a local integer stored on the module with the label LOCAL_VARIABLE
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #6 on: September 26, 2012, 09:10:05 pm »


               

BelowTheBelt wrote...

Yeah, forgot the quotes in my example. Both should have read, GetLocalInt(oArea, "iInt")

Can you give an example of the second scenario, "If on the otherhand iInt is a string, GetLocalInt(oArea, iInt) will look for an integer with a label that matches the string stored in iInt."


string iInt = "Lable";
GetLocalInt(oArea, iInt);
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #7 on: September 26, 2012, 09:24:12 pm »


               Ok.  For some reason, the use of iInt in that string example tripped me up ("i" being typically used to denote an integer).  I was overly complicating my interpretation of your answer.  I was thinking you were illuminating some obscure use to back-trace/set an int from a label (which you weren't), lol.

Thanks for the clarification.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script/Boolean test question ! vs. !=
« Reply #8 on: September 26, 2012, 10:45:27 pm »


               Just to add to what shadow stated.  

if (!GetLocalInt(oArea, iInt) )  

is not the same thing as

if (GetLocalInt(oArea, iInt) != 1)

**********

if (!GetLocalInt(oArea, iInt) )

it is the same as

 if (GetLocalInt(oArea, iInt) == 0 )  

however.  

If you need that expanded on, Just let me know.