ID:152944
 
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.
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.
In response to Wizkidd0123
Thanks.
In response to Broly103
A little tutorial, incase theres something your unsure of.
/*
This wont work because of the duplicate definitions. Just take either
the top or the bottom.
Consider this, the ! opperator means, Not Activated.
For instance:
*/


mob
var
HearSay = 0

mob
verb
Talk(msg as text)
for(var/mob/M in world) //Searches every Mob in the world
if(M.HearSay) //If HearSay is activated, lets them listen
M << "[src] says: [msg]" //Displays the message to a player with HearSay on.

/*
Looking at that, it means the boolean var 'HearSay' is activated.
If a player doesn't have this activated, then they didn't hear your message.
Lets take it a step further.
*/


mob
var
HearSay = 0

mob
verb
Talk(msg as text)
for(var/mob/M in world)
if(M.HearSay)
M << "[src] says: [msg]"

Hear_Say()
if(!src.HearSay) //if(src.HearSay == 0)
src.HearSay = 1 //Activates HearSay
src << "You can now hear world chat." //Tells the player they have.
return //Ends the code so it doesn't exercute the next half.
if(src.HearSay) //if(src.HearSay == 1)
src.HearSay = 0 //Deactivates HearSay
src << "You can no longer hear world chat." //Tells the player.
return //Ends the code.
/*
The ! operator really just makes it easier to work with boolean variables.
if(!something) means if(something == 0) and if(somethingelse) means if(somethingelse == 1)
Thats all there is to it really.
*/
In response to Tiberath
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".
In response to Elation
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.
In response to Wizkidd0123
Wizkidd0123 wrote:
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.

-_-

¬_¬

I think I should stop posting in the developer forums. :p
In response to Tiberath
Tiberath wrote:
The ! operator really just makes it easier to work with boolean variables.
if(!something) means if(something == 0) and if(somethingelse) means if(somethingelse == 1)

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()
src.HearSay = !src.HearSay
src << "You can [src.HearSay ? "now":"no longer"] participate in world chat."
In response to Wizkidd0123
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
usr << "Damn your sexy!"
if(!usr.sexy)
usr << "You've been hit by the ugly stick a lot!"

In response to Farkas
Farkas wrote:
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

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.
In response to Elation
Elation wrote:
The ! operator does not mean "not activated".
It means "not".


I was meaning more for the code i posted. In my example, the ! operator symbolised that Hear_Say was either activated or not activated.