[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
#2

Mkay, edited.
Reply
#3

hmm simple
Reply
#4

Quote:

Once, myself loose indentation caused some problems, my dialog response wasn't working well because of faily indenting

I don't think that has to do with indentation. At least, I used to code with really bad indentation and everything just worked fine. But it does look ugly.
Reply
#5

Nice tutorials and many, many EASY.

you like this: https://sampforum.blast.hk/showthread.php?tid=252966
the first post.
Reply
#6

Thank you.
Reply
#7

Nice Tutorial Mean .
Reply
#8

One thing to do is just ignore them, i get tons of pms from people sending crap about this to me, hopefully this taught them.
Reply
#9

Nice tutorial.
I did the third method years ago

Actually I think you may add some more explanation on why a good indentation is required,
just like better reading, easy to find the missing brackets, etc..
Reply
#10

Good I use tabs ... it's easier x)
Reply
#11

Now i understand it. So #pragma is only for ignoring things? because i have:
#pragma Tabsize 0
#pragma Unused Check
Reply
#12

No, prgama is for passing special instructions to the compiler. Some of those instructions tell the compiler to ignore certain warnings or unused symbols; some can tell users information; some can adjust compiler flags like string type defaults and heap size. Most of them have legitimate uses - even "unused" and "tabsize", sometimes you have a symbol defined and you know that you don't use it but can't make it "stock" for some reason - then "unused" is useful, and both a_samp and YSI use "tabsize" to set it to 4 (YSI uses this to override the warning in some cases where the compiler is wrong without resorting to using 0). For more information check pawn-lang.pdf:

https://sampforum.blast.hk/showthread.php?tid=289258
Reply
#13

Quote:
Originally Posted by Y_Less
View Post
No, prgama is for passing special instructions to the compiler. Some of those instructions tell the compiler to ignore certain warnings or unused symbols; some can tell users information; some can adjust compiler flags like string type defaults and heap size. Most of them have legitimate uses - even "unused" and "tabsize", sometimes you have a symbol defined and you know that you don't use it but can't make it "stock" for some reason - then "unused" is useful, and both a_samp and YSI use "tabsize" to set it to 4 (YSI uses this to override the warning in some cases where the compiler is wrong without resorting to using 0). For more information check pawn-lang.pdf:

https://sampforum.blast.hk/showthread.php?tid=289258
oh thx for the pawn-lang.pdf, this will help me learning the pawno language
Reply
#14

In my PAWNO experience, i can just use #pragma to give specific instructions to the compiler to miss out the errors or it will creep me out by showing me loose indentations, or too many errors on one line. This is also helpful, but not complete enough for me :\
Reply
#15

Quote:
Originally Posted by Superdude
View Post
In my PAWNO experience, i can just use #pragma to give specific instructions to the compiler to miss out the errors or it will creep me out by showing me loose indentations, or too many errors on one line. This is also helpful, but not complete enough for me :\
Yes, that's called ignoring the problems instead of fixing them. If your indentation wasn't bad you wouldn't need to tell the compiler to ignore the badness.
Reply
#16

I fixed all my identitations thx to this tutorial now, thx . +rep

and: Thx Y_Less for explaining me #pragma tabsize 0 only ignores the warnings.
Reply
#17

The one important thing you gain with good indentation is easily avoidable dangling-else problem.(Interestingly this reason is explicitly stated in compiler sources)
Reply
#18

you can use
#pragma tabsize 0
Reply
#19

i in this problem use #pragma tabsize 0 and solved problems with Loose identation
Reply
#20

You people just don't understand the proper usage of #pragma tabsize, do you?

If you're compiler is returning indentation warnings, it means you need to INDENT YOUR CODE. Using #pragma tabsize 0 is a stupid idea and it just shows how lazy you are. If you're going to write code, do it correctly.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)