Hey everyone, in monodevelop how do you indent code? I’ve been noticing that when I’m writing up code it some times looks like the following below and that isn’t very readable. I’ve looked around for an auto indent button but I haven’t found one yet.
{
{
{
}
}
}
tools->options->key bindings and type “indent”.
I just highlight, right click and click the options. The hot key is there too.
Highlight the block of code you want to indent, press TAB
Shift+TAB will unindent
2 Likes
Thanks for the info. I wasn’t quite sure if pressing tab was indenting or not. Also how indent properly so your code can be easily read? For an example I have a large group of beginning and ending curly braces. What is the best way to indent them?
{
{
{
{
{
}
}
}
}
}
This is how my code looks indented
public void ResetAnimator(bool idle, bool dying)
{
if (idle)
{
m_Animator.SetBool("Attack", false);
m_Animator.SetBool("Hit", false);
m_Animator.SetBool("Jump", false);
m_Animator.SetBool("Gangnam", false);
m_Animator.SetFloat("Speed", 0f);
}
else
{
m_Animator.SetBool("Attack", false);
m_Animator.SetBool("Hit", false);
m_Animator.SetBool("Jump", false);
m_Animator.SetBool("Gangnam", false);
if (dying)
{
m_Animator.SetBool("Dying", false);
}
m_Animator.SetFloat("Speed", 0f);
m_Animator.SetFloat("AttackDamageCurve", 0f);
m_Animator.SetFloat("HitDirection", 0f);
m_Animator.SetFloat("AttackType", 0f);
}
}
I always indent code like this but there is no “best way” to indent code, you have to find what you prefer, what you think is easy to read and work with, and use it.
Wow, my stuff did not paste in.
Zeblote:
I always indent code like this but there is no “best way” to indent code, you have to find what you prefer, what you think is easy to read and work with, and use it.
Maybe indenting isn’t my problem then? The bottom of my code looks like the following below and I’m not sure how to fix it and make it readable.
}
}
}
}
}
}
}
}
}
Paste the code so we can see
Thats the way the bottom is suppose to look for that style of formatting.
Indenting helps you spot what code is inside what condition. I like to use comment lines as spacers to better define my blocks of code.
(eg)
var someVar : String;
///========================///
function Start() {
//------------//
if(someVar=="ooo") {
//------------//
if(someVar=="ooo") {
//------------//
someVar = "Sweet formatting style Mantis";
//------------//
}
//------------//
}
//------------//
}
///========================///
When i’m trying to save space I skip the spacers and even break format with something like this
if(someVar=="yo") {
if(someVar=="yoyo") { someVar = "save some space"; } // Hello
}
Why save space? Classes should never be that big if they are set to do one specific job only.