[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
#2

Nice tut, but you should make it with multiarray (3d array too) array[][] and array[][][]
Reply
#3

Okay..Will add it when i have time
Reply
#4

wiki.sa-mp.com
Why you made this tutorial?everyone can find those stuff at wiki.sa-mp.com
(ALL OF YOUR TUTORIALS are useless since we can find them on wiki )
Reply
#5

Nice.
Reply
#6

Copy/Pasting stuff from the AlliedModder's wiki and posting it here without giving credit to them is not a tutorial. That's plagiarism.

http://wiki.amxmodx.org/Pawn_Tutorial#Arrays
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)