View Single Post
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-17-2017 , 15:22   Re: [ TUT ]Dynamic Array
Reply With Quote #26

Quote:
Originally Posted by addons_zz View Post
No. If you set the size to 7, you can store arrays within 7 cell entries.
Code:
// Max cell entries = 7 new Array:array = ArrayCreate( 7 ) new max_array[] = { 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647 } ArrayPushArray( array, max_array )
The max value you can story in a array, or pawn variable (also known as Pawn cell) is the value of the max signed integer of 4 bytes (cellsize of 4 bytes), which is here 2.147.483.647
Code:
// Max cell entries = 1 new Array:array = ArrayCreate( 1 ) new max_interger = 2147483647 ArrayPushCell( array, max_interger )

The word cellsize is misleading, the cellsize should means how many bytes a single Pawn cell (an ordinary variable) can hold on. Here each Pawn cell has the `cellsize` of 4 bytes, which means it can hold signed integers until `2.147.483.647`.
If you still do not understand read:
  1. https://en.wikipedia.org/wiki/Integer_(computer_science)
  2. https://github.com/compuphase/pawn/raw/master/doc/Pawn_Language_Guide.pdf
These examples confused me even more.. Why did you use ArrayPushArray while Hamlet used ArrayPushCell? And why is the size 1 in Hamlet's example and not 10
PHP Code:
#include < amxmodx >

//Create a new variable, it's tagged as Array, so it's for a dyn array
new Array: g_aArray

public plugin_init( )
{
    
register_plugin"CellArray Example""0.1""HamletEagle" )
    
        
//Create our array
    
g_aArray ArrayCreate)
    
    
register_srvcmd"cellarray_writetest""ServerCommand_WriteToArray" )
    
register_srvcmd"cellarray_readtest""ServerCommand_ReadFromArray" )
}

public 
plugin_end( )
{
        
//Destroy our array
    
ArrayDestroyg_aArray )
}

public 
ServerCommand_WriteToArray( )
{
    
//A constant to store some numbers
    
new szConst[ ] = { 012345678}
    
    
//Create a for loop
    
for( new isizeof szConsti++ )
    {
        
//Add everything to the array
        
ArrayPushCellg_aArrayszConst] )
    }
}

public 
ServerCommand_ReadFromArray( )
{
    
//A for loop from 0 to arraysize
    
for( new iArraySizeg_aArray ); i++ )
    {
        
//Print what's stored into dyn array
        
server_print"Number: %i"ArrayGetCellg_aArray) )
    }

__________________
edon1337 is offline