L'indentation permet une meilleur lisibilité du code présenté.
Cela donne plus envie à une personne de lire et de comprendre ton code sans avoir à le déchiffrer !
Indentation:
Très souvent utilisée en programmation, elle rend le code source plus clair et plus lisible.
- Wikipedia.org
EDIT: Voici trois code identique mais qui sont indenté différemment.
Tu pourra me dire quelle est pour toi la meilleur chose à faire: indenter ou ne pas indenter.
Code indenté
if(CPS_IsPlayerInCheckpoint(playerid, cpammu2)) {
AMMUBOX[playerid] = 0;
if(gTeam[playerid] != COP && gTeam[playerid] != Medic && gTeam[playerid] != SWAT && gTeam[playerid] != FBI && gTeam[playerid] != ARMY) {
if(Ammu2RecentlyRobbed == 0) {
new chances = random(500);
if(chances >= 0 && chances <= 400) {
new string[250];
RobAmmu2[playerid] = 20;
Ammu2RecentlyRobbed = 150;
format(string, sizeof(string), "%s[ID:%d] started a robbery at Ammunation!", name, playerid);
Announce(string);
return true;
}
else if(chances >= 401 && chances <= 500) {
new copmsg[250];
SendClientMessage(playerid, ERROR, "Your attempt to rob Ammunation failed!");
SendClientMessage(playerid, ERROR, "The Police are on their way to the store.");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 5);
format(copmsg, sizeof(copmsg), "[HQ] %s attemped to rob Ammunation.", name);
SendRadioMessageToCops(copmsg);
Ammu2RecentlyRobbed = 100;
return true;
}
}
else if(Ammu2RecentlyRobbed > 0) return SendClientMessage(playerid, ERROR, "Ammunation has been robbed recently!");
}
else SendClientMessage(playerid, ERROR, "Your team cannot rob anything.");
}
Code non-indenté
if(CPS_IsPlayerInCheckpoint(playerid, cpammu2))
{
AMMUBOX[playerid] = 0;
if(gTeam[playerid] != COP && gTeam[playerid] != Medic && gTeam[playerid] != SWAT && gTeam[playerid] != FBI && gTeam[playerid] != ARMY)
{
if(Ammu2RecentlyRobbed == 0)
{
new chances = random(500);
if(chances >= 0 && chances <= 400)
{
new string[250];
RobAmmu2[playerid] = 20;
Ammu2RecentlyRobbed = 150;
format(string, sizeof(string), "%s[ID:%d] started a robbery at Ammunation!", name, playerid);
Announce(string);
return true;
}
else if(chances >= 401 && chances <= 500)
{
new copmsg[250];
SendClientMessage(playerid, ERROR, "Your attempt to rob Ammunation failed!");
SendClientMessage(playerid, ERROR, "The Police are on their way to the store.");
SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 5);
format(copmsg, sizeof(copmsg), "[HQ] %s attemped to rob Ammunation.", name);
SendRadioMessageToCops(copmsg);
Ammu2RecentlyRobbed = 100;
return true;
}
}
else if(Ammu2RecentlyRobbed > 0) return SendClientMessage(playerid, ERROR, "Ammunation has been robbed recently!");
}
else SendClientMessage(playerid, ERROR, "Your team cannot rob anything.");
}
Code non-indenté et mal rangé
if(CPS_IsPlayerInCheckpoint(playerid, cpammu2)){AMMUBOX[playerid] = 0;
if(gTeam[playerid] != COP && gTeam[playerid] != Medic && gTeam[playerid] != SWAT && gTeam[playerid] != FBI && gTeam[playerid] != ARMY){if(Ammu2RecentlyRobbed == 0)
{new chances = random(500);if(chances >= 0 && chances <= 400){new string[250];RobAmmu2[playerid] = 20;Ammu2RecentlyRobbed = 150;
format(string, sizeof(string), "%s[ID:%d] started a robbery at Ammunation!", name, playerid);Announce(string);
return true;}else if(chances >= 401 && chances <= 500){new copmsg[250];SendClientMessage(playerid, ERROR, "Your attempt to rob Ammunation failed!");
SendClientMessage(playerid, ERROR, "The Police are on their way to the store.");SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 5);
format(copmsg, sizeof(copmsg), "[HQ] %s attemped to rob Ammunation.", name);SendRadioMessageToCops(copmsg);Ammu2RecentlyRobbed = 100;
return true;}}else if(Ammu2RecentlyRobbed > 0) return SendClientMessage(playerid, ERROR, "Ammunation has been robbed recently!");
}else SendClientMessage(playerid, ERROR, "Your team cannot rob anything.");}
Tu pourra remarquer que le dernier code est très petit (en ligne) mais est complètement illisible !
PS: Code tiré aléatoirement du gamemode RuNix's Cops and Robbers codé par Raul_Ro du forum officiel de SA:MP.