24.02.2015, 01:14
(
Последний раз редактировалось Diogo123; 01.04.2015 в 02:52.
)
Learning to tabulate their codes
Good evening members of the forum samp,I bring to you a tutorial of tabular codes. Many leave their codes in a way that are impossible to understand, and finally even 30% of these people post gamemodes and filterscripts this way where if you have a code confusing and poorly organized in this tutorial I will be trying to explain the reasons to leave your code more 'legible' and move on ways to do this and we're going to start - Flying tabulated
- Examples of codes legible
- Lose identation
- F.A.Q
- Credits
In a way it hides the warnings n but the code is still ugly and virtually impossible to wants.
Example :
pawn Код:
if(!strcmp(cmdtext,"/shith", true)){ if(IsPlayerAdmin(playerid))
{ return 0; }
SendClientMessageToAll(-1,"?? OMG");
return 1;
}
Not to mention the fact that there are codes even more complicated to be seen another example and this here
pawn Код:
CMD:vn(playerid,params[]) {
if(!IsPlayerSpawned(playerid)) { return 1; }
SetPlayerInterior(playerid,0); SetPlayerVirtualWorld(playerid,0);
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
SetVehiclePos(GetPlayerVehicleID(playerid),1464.9005,-889.5593,55.5248+10); SetVehicleZAngle(GetPlayerVehicleID(playerid),272.2324);
} else { SetPlayerPos(playerid,1464.9005,-889.5593,55.5248); SetCameraBehindPlayer(playerid); SetPlayerFacingAngle(playerid,272.2324); }
format(string2, sizeof(string2),"Kick Ass this -> {F81414}[/VN]",GetNick(playerid), playerid);
SendClientMessageToAll(LARANJA,string2); SetCameraBehindPlayer(playerid);
return 1;
}
But how can you make a codes that become somewhat more legible and also editavel because and almost impossible to understand anything (at least in my opinion).
And quite simple we will only apply the form of Flying tabulated.
Flying tabulated
Credits to garfield.
pawn Код:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
All codes follow this standard that if we analyze it seems a tower or a building divided into floors.
For those of you who do not understand I will redo our building using the pawn for better understanding of you
See this example :
pawn Код:
if(parameter /* Sinal */ parametros)
{
if(parameter /* signal */ parameter)
{
if(parameter /* signal */ parameter)
{
if(parameter /* signal */ parameter)
{
if(parameter /* signal */ parameter)
{
if(parameter /* signal */ parameter)
{
if(parameter /* signal */ parameter)
{
}
}
}
}
}
}
}
Examples of codes legible
I will be showing the difference between the codes posted at the beginning of the imiquimod and now after tabulation.
pawn Код:
if (!strcmp(cmdtext, "/shith", true))
{
if (IsPlayerAdmin(playerid))
{
return 0;
}
SendClientMessageToAll(-1, "?? OMG");
return 1;
}
The difference in a way ja and clear because the code was much more clean and visible compared to the example at the beginning of the imiquimod.
Let's see the other tabbed code now:
pawn Код:
CMD:vn(playerid, params[])
{
if (!IsPlayerSpawned(playerid))
{
return 1;
}
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
SetVehiclePos(GetPlayerVehicleID(playerid), 1464.9005, -889.5593, 55.5248 + 10);
SetVehicleZAngle(GetPlayerVehicleID(playerid), 272.2324);
}
else
{
SetPlayerPos(playerid, 1464.9005, -889.5593, 55.5248);
SetCameraBehindPlayer(playerid);
SetPlayerFacingAngle(playerid, 272.2324);
}
format(string2, sizeof(string2), "Kick Ass this -> {F81414}[/VN]", GetNick(playerid), playerid);
SendClientMessageToAll(LARANJA, string2);
SetCameraBehindPlayer(playerid);
return 1;
}
It is much more 'legible' being compared with the other.
Let's see another example now a little more using OnDialogResponse:
pawn Код:
if (dialogid == DIALOG_DUELWEAPONS)
{
if (response)
{
switch (listitem)
{
case 0:
{
PrepareDuelWeapon(playerid, 24);
}
case 1:
{
PrepareDuelWeapon(playerid, 25);
}
case 2:
{
PrepareDuelWeapon(playerid, 26);
}
case 3:
{
PrepareDuelWeapon(playerid, 27);
}
case 4:
{
PrepareDuelWeapon(playerid, 28);
}
case 5:
{
PrepareDuelWeapon(playerid, 29);
}
case 6:
{
PrepareDuelWeapon(playerid, 30);
}
case 7:
{
PrepareDuelWeapon(playerid, 31);
}
case 8:
{
PrepareDuelWeapon(playerid, 32);
}
case 9:
{
PrepareDuelWeapon(playerid, 33);
}
case 10:
{
PrepareDuelWeapon(playerid, 34);
}
case 11:
{
PrepareDuelWeapon(playerid, 0);
}
case 12:
{
PrepareDuelWeapon(playerid, 4);
}
case 13:
{
PrepareDuelWeapon(playerid, 8);
}
case 14:
{
PrepareDuelWeapon(playerid, 9);
}
case 15:
{
PrepareDuelWeapon(playerid, 22);
}
case 16:
{
PrepareDuelWeapon(playerid, 23);
}
}
}
return 1;
}
Lose identation
The name ja says by itself and an error codes incorrectly tabulated (examples at the beginning of the imiquimod) where the way to put this notice would be or tabbed your code or using the pragma tabsize
Let's see another example that of notice:
pawn Код:
format(bancheck, sizeof(bancheck),"LARP/Users/%s.ini",plname);
if(dini_Exists(bancheck)){
if(dini_Int(bancheck,"Banned") == 1){
ClearChatbox(playerid, 10);
SendClientMessage(playerid, COLOR_NICERED,"=======================================YOU ARE BANNED=======================================");
SendClientMessage(playerid, COLOR_LIGHTRED,"This Name is banned from this Server, And never was unbanned.");
SendClientMessage(playerid, COLOR_LIGHTRED,"If you wish to be unbanned please visit our website at <changeme>");
SendClientMessage(playerid, COLOR_LIGHTRED,"Ban Evading will result in a Permanent Range Ban.");
SendClientMessage(playerid, COLOR_NICERED,"============================================================================================");
format(msg2,sizeof(msg2),"AdmCmd: %s (%d), Has been banned for Possible Ban Evading",plname,playerid);SendAdminMessage(COLOR_LIGHTRED,msg2);
format(msg2,sizeof(msg2),"AdmCmd: IP %s has been added to the ban list by Anticheat Peter Griffin",playersip);SendAdminMessage(COLOR_WHITE,msg2);
format(msg2,sizeof(msg2),"(%d/%d/%d) [%d:%d:%d] %s Has been kicked by the anticheat for Possible Ban Evading",d,m,y,h,mi,s,plname);
KickLog(msg2);
SetTimerEx("ScriptBan",500,false,"iis",playerid,999,"Ban Evading");
return 0;
}
}
Where the notice shall be given as follows
pawn Код:
Raven's Roleplay 0.3c V4.2\gamemodes\larp.pwn(5717) : warning 217: loose indentation
F.A.Q
Q:Store codes os and highly advisable to pawn ?
R:Not because at least all that it does not focus only on pawn are familiar with other programming languages such as PHP,JAVASCRIPT, DELPHI,CSS,C++ among others,and the tabbed code of valley for all.
Q:How do I let my code tidy ?
R:
Q:I can solve this very well by placing #pragma tabsize 0 at the top?
R:No, so you do not learn the really pawn, you can learn, the more you'll be more difficult wants their own codes. this does not advise there is nobody.
Q:How do I make a good indentation ?
R:To have a good indentation will be necessary you have some editor of programming, (pawno, notepad++ among others) until the windows notepad serves, it more you will not have the same concept of space than the publishers.
Q:Why should I start tabulated my codes ?
R:The indentation is not compulsory, more if you want to follow the path of programr, will have to learn the basics, learn to tabulated.
Q:Is there any site that does this?
R:Yes,http://www.jotaquery.com.br/ferramentas/identar/
Credits
Diogo123
Garfield
For the creator of the site, but did not know the name of the same
--I apologize for my poor level of English