Quote:
Originally Posted by addons_zz
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: - https://en.wikipedia.org/wiki/Integer_(computer_science)
- 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( 1 )
register_srvcmd( "cellarray_writetest", "ServerCommand_WriteToArray" )
register_srvcmd( "cellarray_readtest", "ServerCommand_ReadFromArray" )
}
public plugin_end( )
{
//Destroy our array
ArrayDestroy( g_aArray )
}
public ServerCommand_WriteToArray( )
{
//A constant to store some numbers
new szConst[ ] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
//Create a for loop
for( new i; i < sizeof szConst; i++ )
{
//Add everything to the array
ArrayPushCell( g_aArray, szConst[ i ] )
}
}
public ServerCommand_ReadFromArray( )
{
//A for loop from 0 to arraysize
for( new i; i < ArraySize( g_aArray ); i++ )
{
//Print what's stored into dyn array
server_print( "Number: %i", ArrayGetCell( g_aArray, i ) )
}
}
__________________