Raised This Month: $ Target: $400
 0% 

More array dimensions - Pawn


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-22-2010 , 11:55   More array dimensions - Pawn
Reply With Quote #1

Emp made a solution to get more array dimensions with Arrays with N Dimensions. He used module memory which first is slower and second makes a lot of limits, so I wrote up you an example how to do this in only pawn code.

I also kept the same structure which normal arrays have, so you can use any similiar ways to call the variables:
PHP Code:
FirstArray][ ][ ][ ] = SecondArray][ ][ ][ ][ ]; 
In the example you only see fourth and fifth dimensions but you can use this up to 10 dimensions with the same formula.

Thing more to note is that you can came up with a bug which appears with increment and decrement operators. It comes when you use these operators as an expression with a cell of an array which is passed by defining with both pre and post modes. What the bug does is that the expression returns a wrong value and the variable isn't increased or decremented. You may somehow use the increment and decrement operators as statement without worries.

PHP Code:
/*
     Plugin to test fourth and fifth array dimensions.
*/
#include <amxmodx>
 
#define PLUGIN "More array dimensions - Pawn"
#define VERSION "1.0"
#define AUTHOR "SnoW"
 
#define FIRST_DIMENSION 2
#define SECOND_DIMENSION 3
#define THIRD_DIMENSION 2
#define FOURTH_DIMENSION 3
#define FIFTH_DIMENSION 2
 
#define DIMENSIONS4 THIRD_DIMENSION * FOURTH_DIMENSION
#define DIMENSIONS5 DIMENSIONS4 * FIFTH_DIMENSION
#define array4[%1][%2][%3][%4] dArray4[ %1 ][ %2 ][ FOURTH_DIMENSION * %3 + %4 ]
#define array5[%1][%2][%3][%4][%5] dArray5[ %1 ][ %2 ][ ( FOURTH_DIMENSION * %3 + %4 ) * FIFTH_DIMENSION + %5 ]
 
public plugin_init( )
{
     
register_pluginPLUGINVERSIONAUTHOR );
     
test;
}
 
test( )
{
 
     
//array4
     
new dArray4FIRST_DIMENSION ][ SECOND_DIMENSION ][ DIMENSIONS4 ] =
     {
          {
               { 
01234},
               { 
67891011 },
               { 
121314151617 }
          },
          {
               { 
181920212223 },
               { 
242526272829 },
               { 
303132333435 }
          }
     };
 
     
//array5
     
new dArray5FIRST_DIMENSION ][ SECOND_DIMENSION ][ DIMENSIONS5 ] =
     {
          {
               { 
01234567891011 },
               { 
121314151617181920212223 },
               { 
242526272829303132333435 }
          },
          {
               { 
363738394041424344454647 },
               { 
484950515253545556575859 },
               { 
606162636365666768697071 }
          }
     };     
 
     for( new 
d1d1 FIRST_DIMENSIONd1++ )
     for( new 
d2d2 SECOND_DIMENSIONd2++ )
     for( new 
d3d3 THIRD_DIMENSIONd3++ )
     for( new 
d4d4 FOURTH_DIMENSIONd4++ )
     {
          
server_print"%i"array4d1 ][ d2 ][ d3 ][ d4 ] );
 
          for( new 
d5d5 FIFTH_DIMENSIONd5++ )
          {
               
server_print"%i"array5d1 ][ d2 ][ d3 ][ d4 ][ d5 ] );
          }
     }
 

SnoW is offline
Send a message via MSN to SnoW
 



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 21:15.


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