Raised This Month: $32 Target: $400
 8% 

Variable with 2 index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 04-03-2016 , 16:01   Variable with 2 index
Reply With Quote #1

Hi

I stoped programing months ago and now i see that I dont remember a lot that i learned of amxx

Just a simple question:

How do I reset a variable with 2 index (like g_points[33][33])?
__________________
skz is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-03-2016 , 16:16   Re: Variable with 2 index
Reply With Quote #2

for( new i = 0; i++; i < 33 )
g_points[ i ][ i ] = 0;

Last edited by Kowalsky; 04-03-2016 at 16:16.
Kowalsky is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-03-2016 , 16:30   Re: Variable with 2 index
Reply With Quote #3

Quote:
Originally Posted by Kowalsky View Post
for( new i = 0; i++; i < 33 )
g_points[ i ][ i ] = 0;
That's wrong.

PHP Code:
new TheArray33 ][ 33 ];
    
//Clear the second dimension only (for a single player)
arraysetTheArrayid ] , sizeofTheArray[] ) );
        
//Clear the entire array
for ( new sizeofTheArray ) ; i++ )
    for ( new 
sizeofTheArray[] ) ; p++ )
        
TheArray][ ] = 0
__________________

Last edited by Bugsy; 04-03-2016 at 18:57.
Bugsy is online now
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 04-03-2016 , 16:42   Re: Variable with 2 index
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
That's wrong.

PHP Code:
new TheArray33 ][ 33 ];
    
//Clear the second dimension only (for a single player)
arraysetTheArrayid ] , sizeofTheArray[] ) );
        
//Clear the entire array
for ( new sizeofTheArray ) ; i++ )
    for ( new 
sizeofTheArray[] ) ; p++ )
        
TheArray][ ] = 0
Thanks, I did in another away but in your way is more efficient
__________________
skz is offline
skz
Senior Member
Join Date: Jul 2014
Location: Portugal
Old 04-03-2016 , 16:57   Re: Variable with 2 index
Reply With Quote #5

problem solved
__________________

Last edited by skz; 04-03-2016 at 17:34.
skz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-03-2016 , 18:29   Re: Variable with 2 index
Reply With Quote #6

I just realized that Kowalsky's code is in fact fine. It would only be an issue if the array dimensions were of a different size, but in this case they are both sized at 33 so it works just fine. My apologies
__________________

Last edited by Bugsy; 04-03-2016 at 18:57.
Bugsy is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-03-2016 , 18:49   Re: Variable with 2 index
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
I just realized that Kowalsky's code is in fact fine. It would only be an issue if the array dimensions were of a different size, but in this case they are both sized at 33 so it works just fine. My apologies
His code only sets the diagonal of the array. Which is only 33 of the 1089 cells in the array.
__________________

Last edited by fysiks; 04-03-2016 at 18:51.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-03-2016 , 18:57   Re: Variable with 2 index
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
His code only sets the diagonal of the array. Which is only 33 of the 1089 cells in the array.
Ah, you're right lol. I should have trusted my original thought.
__________________

Last edited by Bugsy; 04-03-2016 at 18:58.
Bugsy is online now
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-03-2016 , 18:59   Re: Variable with 2 index
Reply With Quote #9

Ah yeah, damn. Sorry, my bad. Bugsy and fysiks are for sure right here!
Kowalsky is offline
Reply


Thread Tools
Display Modes

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 20:38.


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