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?
Script/Boolean test question ! vs. !=
Débuté par
BelowTheBelt
, sept. 26 2012 06:54
#1
Posté 26 septembre 2012 - 06:54
#2
Posté 26 septembre 2012 - 07:01
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.
2) will be TRUE always as long as the value isnt 1, but can be 2, -1 etc.
#3
Posté 26 septembre 2012 - 07:15
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.
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 .
#4
Posté 26 septembre 2012 - 07:20
Many thanks. That was my understanding. And just to clarify, if a variable is unset, GetLocalInt will return 0, correct?
#5
Posté 26 septembre 2012 - 07:35
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."
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."
#6
Posté 26 septembre 2012 - 08:07
(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
(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
#7
Posté 26 septembre 2012 - 08:10
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);
#8
Posté 26 septembre 2012 - 08:24
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.
Thanks for the clarification.
#9
Posté 26 septembre 2012 - 09:45
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.
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.





Retour en haut






