SA-MP Forums Archive
Loose indentation? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loose indentation? (/showthread.php?tid=454082)



Loose indentation? - Hargrave - 27.07.2013

Look here:
Quote:

public OnPlayerText(playerid, text[])
{
if (realchat)
{
new sendername[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, sendername, sizeof(sendername));
sendername[strfind(sendername,"_")] = ' ';
format(string, sizeof(string), "%s says: %s", sendername, text);
ProxDetector(30.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_F ADE4,COLOR_FADE5);
new lengthtime = strlen(text);
new time = lengthtime*50;
ApplyAnimation(playerid,"PED","IDLE_CHAT",4.0,0,0, 0,0,time);
return 0;
}
(LINE 19 return 1;
}

Warning:
Quote:

(19 : warning 217: loose indentation

I cannot understand - what is the problem with that? The command works, but I just don't want to warning.


Re: Loose indentation? - Necip - 27.07.2013

Show us your code on [ pawn ] [ /pawn ] tags, not quote.
O.T: Here you go.
pawn Код:
public OnPlayerText(playerid, text[])
{
    if (realchat)
    {
        new sendername[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, sendername, sizeof(sendername));
        sendername[strfind(sendername,"_")] = ' ';
        format(string, sizeof(string), "%s says: %s", sendername, text);
        ProxDetector(30.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_F ADE4,COLOR_FADE5);
        new lengthtime = strlen(text);
        new time = lengthtime*50;
        ApplyAnimation(playerid,"PED","IDLE_CHAT",4.0,0,0, 0,0,time);
        return 0;
    }
    return 1;
}



Re: Loose indentation? - Hargrave - 27.07.2013

Thanks, and yeah I will add them in pawn instead from now on, but what did you edit? I mean like I cannot see anything different, but it worked.


Re: Loose indentation? - MellowHammer - 27.07.2013

In case you are wondering what is the difference in the code, the code Necip gave you is tabbed correctly. This warning is not very important unless you want to understand the code better and make it look nicer.


Re: Loose indentation? - MP2 - 27.07.2013

The code between two curly brackets (braces) should be tabbed in a level, for example:

pawn Код:
SomeFunction()
{
    if(contition)
    {
        if(some_other_condition)
        {
            // Code
        }
    }
}
It makes code easier to read and makes missing brackets easier to find (although, prevention is better than cure).


Re: Loose indentation? - Necip - 27.07.2013

Quote:
Originally Posted by Hargrave
Посмотреть сообщение
Thanks, and yeah I will add them in pawn instead from now on, but what did you edit? I mean like I cannot see anything different, but it worked.
Your "return 1;" was something like this I think.
WRONG:
pawn Код:
public OnPlayerText(playerid, text[])
{
    if (realchat)
    {
        new sendername[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, sendername, sizeof(sendername));
        sendername[strfind(sendername,"_")] = ' ';
        format(string, sizeof(string), "%s says: %s", sendername, text);
        ProxDetector(30.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_F ADE4,COLOR_FADE5);
        new lengthtime = strlen(text);
        new time = lengthtime*50;
        ApplyAnimation(playerid,"PED","IDLE_CHAT",4.0,0,0, 0,0,time);
        return 0;
    }
return 1;
}
CORRECT:
pawn Код:
public OnPlayerText(playerid, text[])
{
    if (realchat)
    {
        new sendername[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, sendername, sizeof(sendername));
        sendername[strfind(sendername,"_")] = ' ';
        format(string, sizeof(string), "%s says: %s", sendername, text);
        ProxDetector(30.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_F ADE4,COLOR_FADE5);
        new lengthtime = strlen(text);
        new time = lengthtime*50;
        ApplyAnimation(playerid,"PED","IDLE_CHAT",4.0,0,0, 0,0,time);
        return 0;
    }
    return 1;
}