ID:152944
![]() Jun 28 2005, 12:14 pm
|
|
I was wondering if the ! operator was this, usr.hasham==0 but instead of programming it this way you could do it like this !usr.hasham.I'm still kinda confused on what this operator does.
|
![]() Jun 28 2005, 12:29 pm
|
|
I recommend reading the ! operator's section in my article, "Hello, Operator?". =)
|
Yes, you can use it like that, but I'm unsure of the other ways you can use it.
|
A little tutorial, incase theres something your unsure of.
/* |
The ! operator does not mean "not activated".
It means "not". if(foo!=0) It can be used in most situations. Either way, it means "not". |
Elation wrote:
if(foo!=0) That actually isn't the ! operator you're using there -- it's the != operator, which is a completely different operator. |
Wizkidd0123 wrote:
Elation wrote: -_- ¬_¬ I think I should stop posting in the developer forums. :p |
Tiberath wrote:
The ! operator really just makes it easier to work with boolean variables. Well, no. We don't tell people to use if(something) and if(!something) instead of if(something == 1) and if(something == 0) just because the former versions are shorter. if(!something) means if(something == 0 || something == null || something == ""). if(something) means if(something != 0 && something != null && something != ""). That's actually a very big difference. Let's say that my_var is null. Since 0, null, and "" are completely different values, checking for if(my_var == 0) wouldn't cut it. Checking for if(!my_var), however, would. Also, in your mini-demo in the above post, you really should have used else instead of if(!src.HearSay) -- it's much more robust. You don't need return there either. If you wanted to, you could really shorten that up a lot: mob/verb/Hear_Say() |
wow, you guys sure have come up with a lot of code/explanation rather than simply saying true and false
if(!variable) = false if(variable) = true if(usr.sexy)//if the user is sexy |
Farkas wrote:
wow, you guys sure have come up with a lot of code/explanation rather than simply saying true and false While what you said there is true, explaining it that way could be potentially misleading because the constant vars, TRUE and FALSE, are equal to 1 and 0, respectively. By the way, in the snippet you posted, if(!usr.sexy) should be else. |