[Tutorial] How to fix warning 217: loose indentation
#1

How to fix warning 217: loose indentation


Introduction
Recently, I saw A LOT of people asking WHY do they get the warning 217, well, I always had to write examples, and I got sick of wasting my time in doing that, so now I'll just write a tutorial and post the thread link if someone asks.

Why do we get warning 217?
If your code is not properly indented, your compiler will tell you. To fix the warning, all you have to do is properly indent your code.
I have had problems with this in my scripting beginnings. I couldn't see some obvious errors in my code, but once I indented them, I could easily spot issues.
Good indentation is important. If you want some scripter to help you and you give him messy code, don't be surprised if he ignores you.

To indent your code, all you need to do is press the tab key few times, or only one time, depends.

After every "{" (if we open a statement), you need to go one tab forward, by the standards, and if we do "}" (if we close a statement), then we go one tab back. The default tab size in a_samp is 4 spaces (so tab is equal to 4 spaces).

So, here's an example of GOOD indentation:
pawn Код:
if( !strcmp( cmdtext, "/lol", true ) )
{
    // There's a "{" so we moved 4 spaces (one tab) forward.
    if( !strcmp( cmdtext[ 5 ], "rofl", true ) )
    {
        //ANOTHER "{" so we move 4 spaces (one tab) forward
        SendClientMessage( playerid, -1, "Your parameter after the /lol command is 'rofl'." );
    }
    //We closed the bracket, so we go 4 spaces (one tab) back.
    return 1;
}
Now, I hope you've understood it, if not, I'll give an example of BAD indentation:
pawn Код:
if( !strcmp( cmdtext, "/lol", true ) )
{
  if( !strcmp( cmdtext[ 5 ], "rofl", true ) )
     {
   SendClientMessage( playerid, -1, "Your parameter after the /lol command is 'rofl'." );
        }
return 1;
}
Also, here's what alot of people do:
pawn Код:
if( !strcmp( cmdtext, "/lol", true ) )
{
if( !strcmp( cmdtext[ 5 ], "rofl", true ) )
{
SendClientMessage( playerid, -1, "Your parameter after the /lol command is 'rofl'." );
}
return 1;
}
Now that's really unreadable...

That's about it.
Reply


Messages In This Thread
How to fix warning 217: loose indentation - by Mean - 23.05.2011, 08:51
Re: How to fix warning 217: loose indentation - by Mean - 23.05.2011, 16:21
Respuesta: How to fix warning 217: loose indentation - by Host-samp - 23.05.2011, 20:45
Re: How to fix warning 217: loose indentation - by [L3th4l] - 23.05.2011, 20:48
Re: How to fix warning 217: loose indentation - by TheGarfield - 23.05.2011, 20:55
Re: How to fix warning 217: loose indentation - by Mean - 25.05.2011, 09:16
Re: How to fix warning 217: loose indentation - by HyperZ - 25.05.2011, 10:50
Re: How to fix warning 217: loose indentation - by Lorenc_ - 25.05.2011, 11:38
Re: How to fix warning 217: loose indentation - by leong124 - 25.05.2011, 14:47
Re: How to fix warning 217: loose indentation - by Michael@Belgium - 26.05.2011, 07:15
Re: How to fix warning 217: loose indentation - by [WA]iRonan - 16.01.2013, 10:13
Re: How to fix warning 217: loose indentation - by Y_Less - 16.01.2013, 10:25
Re: How to fix warning 217: loose indentation - by [WA]iRonan - 16.01.2013, 10:49
Re: How to fix warning 217: loose indentation - by Superdude - 16.01.2013, 11:59
Re: How to fix warning 217: loose indentation - by Y_Less - 16.01.2013, 12:19
Re: How to fix warning 217: loose indentation - by [WA]iRonan - 17.01.2013, 09:40
Re: How to fix warning 217: loose indentation - by JoBullet - 17.01.2013, 16:06
Re: How to fix warning 217: loose indentation - by Christian7073 - 10.04.2013, 14:45
Respuesta: How to fix warning 217: loose indentation - by sonnkz - 10.04.2013, 18:53
Re: How to fix warning 217: loose indentation - by RealCop228 - 10.04.2013, 19:10
Re: Respuesta: How to fix warning 217: loose indentation - by Ash. - 10.04.2013, 19:16
Re: How to fix warning 217: loose indentation - by MP2 - 11.04.2013, 08:11
Re: How to fix warning 217: loose indentation - by Patrick - 11.04.2013, 09:34
Re: How to fix warning 217: loose indentation - by biduaxe - 29.07.2013, 04:34
Re: How to fix warning 217: loose indentation - by maaz - 05.12.2013, 19:04
Re: How to fix warning 217: loose indentation - by iZN - 05.12.2013, 19:11
Re: How to fix warning 217: loose indentation - by maaz - 05.12.2013, 19:13
Re: How to fix warning 217: loose indentation - by Y_Less - 05.12.2013, 21:32
Re: How to fix warning 217: loose indentation - by maaz - 06.12.2013, 02:53

Forum Jump:


Users browsing this thread: 7 Guest(s)