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

Compiler shows 'loose indentation' despite code being ordered


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-09-2023 , 09:08   Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #1

Hello, this is the warning i get:



This is how the code looks like:



Here is the source code:

Code:
	    // Custom sounds
             new i
    
             for (i = 0; i < ZM_DEATH; i++)
             precache_sound(death_zm[i])
    
             for (i = 0; i < ZM_IDLE; i++)
             precache_sound(idle_zm[i])
    
             for (i = 0; i < ZM_PAIN; i++)
             precache_sound(pain_zm[i])
}
Why does the compiler says the code isn't well ordered? I don't see any disorder. Would you tell me how to fix the warning, please?

Last edited by GlobalPlague; 01-09-2023 at 09:09.
GlobalPlague is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-09-2023 , 10:22   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #2

UPDATE: Problem is solved. I didn't see the problem using the AMXX Studio, but when i opened the code with Notepad, i saw that some of the code is moved a little bit forward, so i deleted some space that was behind the code and now the code is ordered and the compiler doesn't show the warning.
GlobalPlague is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-09-2023 , 16:27   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #3

Because the compiler expects the code to be in curly brackets .
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 01-09-2023 , 17:13   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #4

Display whitespace to see what is going on. Loose from tabbing into spaces. Clearing whitespace helps too as you noted.
PHP Code:
»       ····//·Custom·sounds
·············new·i
····
·············for·
(=·0;·i·<·ZM_DEATH;·i++)
·············precache_sound(death_zm[i])
····
·············for·
(=·0;·i·<·ZM_IDLE;·i++)
·············precache_sound(idle_zm[i])
····
·············for·
(=·0;·i·<·ZM_PAIN;·i++)
·············precache_sound(pain_zm[i])

Pick tabs or spaces but not both.
Code:
·············//·Custom·sounds ·············new·i ·············for·(i·=·0;·i·<·ZM_DEATH;·i++) ·············precache_sound(death_zm[i]) ·············for·(i·=·0;·i·<·ZM_IDLE;·i++) ·············precache_sound(idle_zm[i]) ·············for·(i·=·0;·i·<·ZM_PAIN;·i++) ·············precache_sound(pain_zm[i]) }
__________________
DJEarthQuake is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-09-2023 , 21:27   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #5

Use tabs. Show whitespace. Much easier to maintain proper indentation.

Quote:
Originally Posted by Natsheh View Post
Because the compiler expects the code to be in curly brackets .
I actually don't think that if there is only a single line that the compiler cares (though the person should care). I dislike not using braces most of the time. I basically only skip braces when I'm returning a value and ending the function execution.
__________________
fysiks is online now
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-10-2023 , 04:26   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #6

Quote:
Originally Posted by DJEarthQuake View Post
Display whitespace to see what is going on. Loose from tabbing into spaces. Clearing whitespace helps too as you noted.
PHP Code:
»       ····//·Custom·sounds
·············new·i
····
·············for·
(=·0;·i·<·ZM_DEATH;·i++)
·············precache_sound(death_zm[i])
····
·············for·
(=·0;·i·<·ZM_IDLE;·i++)
·············precache_sound(idle_zm[i])
····
·············for·
(=·0;·i·<·ZM_PAIN;·i++)
·············precache_sound(pain_zm[i])

Pick tabs or spaces but not both.
Code:
·············//·Custom·sounds ·············new·i ·············for·(i·=·0;·i·<·ZM_DEATH;·i++) ·············precache_sound(death_zm[i]) ·············for·(i·=·0;·i·<·ZM_IDLE;·i++) ·············precache_sound(idle_zm[i]) ·············for·(i·=·0;·i·<·ZM_PAIN;·i++) ·············precache_sound(pain_zm[i]) }
By "whitespace" you mean empty space created with the SPACE button, instead of with the Tab button? Well, i wasn't aware that the Tab button creates a single empty space of the size the compiler needs. Until recently, i was creating empty space with the SPACE button or by copying already existing empty and putting it where there should be empty space.

And i didn't understand what you mean by pick tabs or spaces but not both. And what do the point you added to the code mean?

Last edited by GlobalPlague; 01-10-2023 at 04:27.
GlobalPlague is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-10-2023 , 04:33   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Because the compiler expects the code to be in curly brackets .
The code already has a curly bracket at the end. Should there be more curly brackets? If yes, where should they be?

Quote:
Originally Posted by fysiks View Post
Use tabs. Show whitespace. Much easier to maintain proper indentation.

I actually don't think that if there is only a single line that the compiler cares (though the person should care). I dislike not using braces most of the time. I basically only skip braces when I'm returning a value and ending the function execution.
Yes, now i know i should do this.

Last edited by GlobalPlague; 01-10-2023 at 04:39.
GlobalPlague is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-10-2023 , 12:26   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #8

PHP Code:
for(...)
statement 
is valid from the point of view of the compiler. However, as mentioned above, it is not a great idea.

A more readable version is:
PHP Code:
for(...)
{
    
statement

__________________

Last edited by HamletEagle; 01-10-2023 at 12:26.
HamletEagle is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 01-11-2023 , 16:17   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
for(...)
statement 
is valid from the point of view of the compiler. However, as mentioned above, it is not a great idea.

A more readable version is:
PHP Code:
for(...)
{
    
statement

So, the following code:

PHP Code:
        // Custom sounds
             
new i
    
             
for (0ZM_DEATHi++)
             
precache_sound(death_zm[i])
    
             for (
0ZM_IDLEi++)
             
precache_sound(idle_zm[i])
    
             for (
0ZM_PAINi++)
             
precache_sound(pain_zm[i])

...actually should be like this:

PHP Code:
        // Custom sounds

}
             new 
i
    
             
for (0ZM_DEATHi++)
             
precache_sound(death_zm[i])
    
             for (
0ZM_IDLEi++)
             
precache_sound(idle_zm[i])
    
             for (
0ZM_PAINi++)
             
precache_sound(pain_zm[i])

Correct?
GlobalPlague is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-12-2023 , 02:12   Re: Compiler shows 'loose indentation' despite code being ordered
Reply With Quote #10

Quote:
Originally Posted by GlobalPlague View Post
By "whitespace" you mean empty space created with the SPACE button, instead of with the Tab button? Well, i wasn't aware that the Tab button creates a single empty space of the size the compiler needs. Until recently, i was creating empty space with the SPACE button or by copying already existing empty and putting it where there should be empty space.

And i didn't understand what you mean by pick tabs or spaces but not both. And what do the point you added to the code mean?
The term "whitespace" most often refers to both spaces and tabs. You can look up the term for more info but in this context (indentation) we're talking about just spaces and tabs.

When indenting code, you are generating whitespace for the purpose of making the code more readable by putting code that is in a different scope in at a different indentation depth. You can create indentation white space using either tabs OR spaces. If you try to mix tabs AND spaces together, it will most often create inconsistent indentation because tabs are variable in size while spaces are not. I like tabs because two different people working on the same code can set up their editors to display the tab character as different sizes (some people like to have more space).


Quote:
Originally Posted by GlobalPlague View Post
So, the following code:

PHP Code:
        // Custom sounds
             
new i
    
             
for (0ZM_DEATHi++)
             
precache_sound(death_zm[i])
    
             for (
0ZM_IDLEi++)
             
precache_sound(idle_zm[i])
    
             for (
0ZM_PAINi++)
             
precache_sound(pain_zm[i])

...actually should be like this:

PHP Code:
        // Custom sounds

}
             new 
i
    
             
for (0ZM_DEATHi++)
             
precache_sound(death_zm[i])
    
             for (
0ZM_IDLEi++)
             
precache_sound(idle_zm[i])
    
             for (
0ZM_PAINi++)
             
precache_sound(pain_zm[i])

Correct?
No, he means:
PHP Code:
             for (0ZM_DEATHi++)
             {
                          
precache_sound(death_zm[i])
             } 
__________________
fysiks is online now
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 15:19.


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