[Tutorial] Creating cleaner and more read-able code
#15

Quote:
Originally Posted by Gammix
View Post
Proper form of Control Structures.
You have added the general ones (>, !, ==) but what about Triadic opreators (? & !
These would help to shorten the code. Just for an example:
Code:
new bool:x[2];
main()
{
       x[0] = true;
       if(x[0])
       {
                x[1] = true;
        }
        else 
        {
                x[1] = false;
         }
}
Now that code can also be written as:
Code:
new bool:x[2];

main()
{
        x[1] = (x[0] == true) ? (true) : (false);
}
Though you can also do that^^ with more vars.

Implementing in a pm script:
Code:
CMD:togglepm(playerid, params[])
{
        pm[playerid] = ( pm[playerid] == true ) ? ( false ) : ( true );
        return 1;
}
If you just want to swap a boolean value you might as well just do.
Code:
var = !var;
I don't really like the way people put all their "pre-command checks" on a single line. In the case of those "pre-command checks" I put the check, then the return indented on the line below follwed by a blank line. I always have an extreme urge to line everything up. Especially in case of coordinates. It will usually look like this (screenshot to preserve identation): http://puu.sh/guaXZ/59b9cad49e.png
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)