[Tutorial] Pawn Language Tutorial[Arrays]
#1

Arrays
Pawn features basic "arrays". An array is a simple type of aggregate data. This means you can store multiple values in one variable! An array follows the same rules as a regular variable, and it has the same types. It simply can contain multiple values. You define an array with brackets, and how many values it can hold. For example:
pawn Код:
//This will declare a variable called "Players" which holds 32 numbers.
new Players[32]
 
//You can now store values in any of the 32 "slots" this array has.  
// The slots are numbered from 0 to n-1, or in this case, 0 to 31.
//Every slot starts off as 0.
 
//Set slot 0 to 5
Players[0] = 5
 
//Set slot 1 to whatever is in slot 0, in this case, the number 5
Players[1] = Players[0]
 
//This is invalid!
//Although there are 32 slots, they are numbered from 0 to 31.
//Doing this results in AMX Native Error 4 - AMX_ERR_BOUNDS
// or, it simply won't compile!
Players[32] = 15
 
//This is also totally invalid          
Players[-1] = 6
 
new a = 3
//This is also totally invalid.  
//a must be a constant number.
new BadArray[a]
 
//So this is valid:
const b = 3
new GoodArray[b]
 

 
#define ARRAY_SIZE 3
new Array[ARRAY_SIZE]
Arrays can also be declared with groups of data default, such as:
pawn Код:
new Numbers[4] = {0,1,2,3}
//Note: it is important that you make sure the amount of numbers
// you pass and the size of the array match
We can also use any data type with arrays
pawn Код:
//Array of floating points:
new Float:Numbers[4] = {0.0, 1.2, 2.4, 3.8}
//Array of booleans.  Note this sets every slot to true.
new bool:playerHasGun[33] = {true, ...}
thanks to alliedmodders wiki

This was a short tutorial..Hope you like it.
Thanks.
Reply


Messages In This Thread
Pawn Language Tutorial[Arrays] - by [HK]Ryder[AN] - 31.08.2012, 13:37
Re: Pawn Language Tutorial[Arrays] - by CoaPsyFactor - 31.08.2012, 16:47
Re: Pawn Language Tutorial[Arrays] - by [HK]Ryder[AN] - 01.09.2012, 02:33
Re: Pawn Language Tutorial[Arrays] - by Johnson_Brooks - 01.09.2012, 02:45
Re: Pawn Language Tutorial[Arrays] - by Lordzy - 01.09.2012, 02:51
Re: Pawn Language Tutorial[Arrays] - by ReneG - 01.09.2012, 03:56

Forum Jump:


Users browsing this thread: 2 Guest(s)