31.08.2012, 13:37
(
Последний раз редактировалось [HK]Ryder[AN]; 08.09.2012 в 16:50.
)
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:
Arrays can also be declared with groups of data default, such as:
We can also use any data type with arrays
thanks to alliedmodders wiki
This was a short tutorial..Hope you like it.
Thanks.
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]
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
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, ...}
This was a short tutorial..Hope you like it.
Thanks.