ID:151614
 
. = ..()
!

These symbols, I've read the book definitions but I don't exaclty get the point of them or if they would ever even be necesary. Maybe someone could elaborate. I mean like, !, isnt it either a 0 or a 1? So instead you could define a variable either equaling 0 or 1? Please elaborate, and thank you!
An exclamation mark (!) means NOT.
Everything in programming is basically true or false. False is 0, an empty text string ( "" ) and an uninitialized variable. Everything else is true (1 is true, 100 is true, 138.299 is true, even "hello" is true).

You most commonly use it for comparisons. Rather than checking "if(something==1)" or "if(something==0)" you can check "if(something)" and "if(!something)".
It is safer to use the second method, because if something is not 1 or 0, the code breaks, but using ! it is impossible for the code to break because it is either true or false.

One example I often use is for status effects. Several might for example stop movement. Rather than checking for each of these status effects (and more) everytime someone attempts to move, I use one variable called CanMove.
If CanMove is false then they can move. If it is true, they cannot move.
Everytime a status effect is added, CanMove increases by 1, everytime one is removed, it is decreased by 1. So if I check if(CanMove), no matter how many status effects are active, the check will always be accurate, because it will be true. So movement does not happen.
If I do this, provided I do not add or subtract to CanMove improperly the code cannot break, and I do not need tons of variables, nor do I need to check tons of different things to see if movement is allowed or not.

Probably not the best description, or example. But when possible you should avoid using if(something==0) and try to use !.
.=..() is actually two operations: first it calls ..(), then it assigns the result to .

..() calls the parent of a procedure. If you override a procedure, ..() is what will call the proc you just overrode. So, you would use it when you want to do something in ADDITION to the default. For example:

mob
verb/dance()
usr << "You dance."
dancer
dance()
..()
usr << "Everybody is very impressed."


. is the default return value. Whatever you assign to it, the procedure will return when it ends.

The two are used together in .=..() in cases where you want to perform the default action AND preserve the default return value. A common example is Move():

mob
Move()
.=..()
//if the move was successful:
if(.)
//do something


as Move() returns a value indicating success or failure, it's important to maintain that.

As for the ! operator, that just returns the opposite of something. In the Move() example, you would use if(!.) to do something when the move WASN'T successful.
In response to Garthor
Ok, thats much better, thank you =D. How would I make it so that move only runs on 1 direction just to show an example for a self reminder? =)
In response to Darkjohn66
mob/Move(newloc)
if(get_dir(src,newloc) == NORTH)
return ..()
else
return 0