Raised This Month: $51 Target: $400
 12% 

[TUT][HQ] Indenting your code in proper way!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joelverghese
Member
Join Date: Oct 2011
Old 05-13-2014 , 06:19   [TUT][HQ] Indenting your code in proper way!
Reply With Quote #1


Introduction
Hey there AM,
So I found many new beginners making a mistake of making the code poorly Indenting, and so I made

this small tutorial to help them fix this small problem.
Here's what Fysiks wrote
Quote:
Originally Posted by fysiks View Post
  1. You should search before posting. This has been ask no less than a million times

    before.
  2. You can ignore them if you really want to do so.
  3. You should use a consistent indentation

    style
    .
So I thought why to ignore that? Also why not to make a small guide so that every time a

person face this problem he/she might find this tutorial helpful and get's it fixed !



So let's begin ,

Warning that you will receive is
Quote:
warning 217: loose indentation
The Code that is badly indented
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <hamsandwich>

public plugin_init() {
        
RegisterHam(Ham_Spawn"player""gunsfort"1)
}

public 
gunsfortid ) { 
if(
cs_get_user_team(id)==CS_TEAM_T) { 
        
strip_user_weaponsid ); 
        
give_itemid"weapon_ak" );
        
give_itemid"weapon_deagle" );
        
give_itemid"weapon_knife" ); 
        
cs_set_user_bpammoid35CSW_DEAGLE  );
        
cs_set_user_bpammoid90CSW_AK47  );

    }
    return 
PLUGIN_HANDLED

When we compile this code it would show us this warning


So let's fix this code now !

To do that we need
1.Brain
2.Notepad++
3.AMXx Studio


So let's begin,
Notepad++
Fixing the above code using Notepad++
1. Download

Notepad+

+
.
2. Install TextFX plugin in notepad++
3. To install the plugin follow my instructions
  • Extract the file named(anywhere you wish) TextFX.v0.26.unicode.bin.zip
  • Now after extraction you will find a file named NppTextFX.dll
  • Copy that dll and paste it here (your directory:\Notepad++\plugins\NppTextFX.dll)
  • Restart Notepad++ and your done.

So now let's get back on indenting our badly indented plugin and to do so follow the below

given image.


Note-It's still not indented because i have not pressed the re-indent c++ code option



Let's get the indented code after pressing the option Re-indent C++ Code.


Now when you compile this plugin you will get this as a result


you might clearly see the difference in these two images that is when we don't press the

Re-Indent C++ Code option it like this


but when i press Re-indent C++ Code we get something like this


AMXx Studio
Now let's indented the same code using AMXx Studio.
To do that we have to
1.Open AMXx Studio
2.Paste the code in AMXx Studio
3.Go to tools and then press the option called Indenter
Ok let's do it

Note-This Code is NOT indented because I have not pressed the Indenter option.

Now let's press the Indenter option and get the Indented Code


Now when we compile the Indented Code we will get this as a result


Conclusion-

Indentation makes your code look good and easy to read.
What I recommend it to always use Notepad++ for Indenting your code as it will fix all the

indentation problems.

Last edited by joelverghese; 05-13-2014 at 10:09. Reason: Update !
joelverghese is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-13-2014 , 06:29   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #2

Not a bad tutorial, I guess it might help some people who just copy paste several plugins together and it looks like absolute garbage.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
skype321
Member
Join Date: Mar 2014
Old 05-13-2014 , 06:33   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #3

Good job my friend.
skype321 is offline
joelverghese
Member
Join Date: Oct 2011
Old 05-13-2014 , 08:31   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #4

Quote:
Originally Posted by Backstabnoob View Post
Not a bad tutorial, I guess it might help some people who just copy paste several plugins together and it looks like absolute garbage.
hmm you are right. I hope it helps others who need it ;)
joelverghese is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-13-2014 , 12:12   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #5

AFAIK the indentation of TextFX does not work without brackets.
I have not found an option for it at least.
For example:
Code:
if ( true )    return
Would become:
Code:
if ( true ) return

Just thought that it should be mentioned.
__________________

Last edited by Black Rose; 05-13-2014 at 12:16.
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-13-2014 , 12:34   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #6

Quote:
Originally Posted by Black Rose View Post
AFAIK the indentation of TextFX does not work without brackets.
I have not found an option for it at least.
For example:
Code:
if ( true )    return
Would become:
Code:
if ( true ) return

Just thought that it should be mentioned.
Always use braces . . .
__________________
fysiks is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 05-13-2014 , 12:37   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #7

I like doing:
PHP Code:
if (true) return; 
or better yet
PHP Code:
if (true) { return; } 
;D
__________________
ddhoward is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 05-13-2014 , 19:15   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #8

Sometimes Amxx studio can trouble with auto ident code
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
joelverghese
Member
Join Date: Oct 2011
Old 05-13-2014 , 22:37   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #9

Quote:
Originally Posted by ^SmileY View Post
Sometimes Amxx studio can trouble with auto ident code
i can't really understand what are you trying to say but , if your saying that AMXx Studio creates a problem in indenting the code then your right

Last edited by joelverghese; 05-13-2014 at 22:37.
joelverghese is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 05-13-2014 , 23:31   Re: [TUT][HQ] Indenting your code in proper way!
Reply With Quote #10

Try to indent a private function on AMXx Studio, and you'll see a wonderful bug
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode