Documentation

Mokoi Gaming uses [http://compuphase.com/pawn/pawn.htm Pawn] as default scripting language, so further references to Pawn will also refer to the default scripting language.

Variables must be declared before they are used in an expression. Pawn is a type-less language, all variables are 'Cell' or a group of 'Cell'. A Cell can hold 32-bit integral number.

Type of Declarations

Local declarations

A local declaration appears inside a compound statement. A local variable can only be accessed from within the compound statement, and from nested compound statements. A declaration in the expression of a for loop instruction is also a local declaration. Taken from Pawn's Manual

Global declarations

A global declaration appears outside a function and a global variable is accessible to any function. Global data objects can only be initialised with constant expressions. Taken from Pawn's Manual

Static declarations

Static declaration variable are added to global scope.
add2Static()
{
   //add one to staticvar from main() function
   staticvar++;
}

main()
{
  new localvar; //Can only in this function.
  static staticvar; // Statics variable are added to global scope.
  add2Static();
}

Stock declarations

Stock declaration variable or function may not be include in the compiled output if they aren't being used

Public declarations

Public declaration function can be access outside of the script, either by the program or other entity.

Initialisation

Variables can be initialised at their declaration. Uninitialised data defaults to zero.
Examples:
new i = 1
new j /* j is zero */
new k = 'a' /* k has character code for letter 'a' */
new a[] = {1,4,9,16,25} /* a has 5 elements */
new s1[20] = {'a','b'} /* the other 18 elements are 0 */
new s2[] = "Hello world..." /* a unpacked string */
new s3[] = !"Hello world..." /* a packed string */
new s4[14 char] = !"Hello world..." /* a packed string */
new b[10]= {1,2,...} /* b=1,2,3,4,5,6,7,8,9,10 */
Examples of invalid declarations
new c[3] = 4 /* an array cannot be set to a value */
new i = "Good-bye" /* i must be an array for this initialisers */
new q[] /* unknown size of array */
new p[2] = { i + j, k - 3} /*array initialisers must be constants */

Integrals/Numbers

Integrals are the basic variable type in Pawn. These can hold a whole number value between −2,147,483,648 and +2,147,483,647.

Arrays

Arrays are a group of Cells.

2D Arrays

2D Arrays are just a Array of Arrays

Strings

A string is just a array with a terminating 0. Characters are stored as UTF-32 in the array.
// Valid Examples
new a0[6] = "valid";
new a1[6] = {'v', 'a', 'l', 'i', 'd', 0 };
new a2[6] = {118, 97, 108, 105, 100, 0 };
// Invalid Examples
new b1[6] = {'v', 'a', 'l', 'i', 'd' }; // Invalid string, but valid Array

Packed Strings

In a unpacked string, each Cell store the ASCII character value (7bit), since each Cell can hold a 32bit value, a packed string takes advanced of that and stores multiply character value in one Cell.
new author[3] = {1819634533,2013265920, 0 }; // This this a packed string that says 'lukex'.
new author[3] = !"lukex"; // ! before the string will pack the string.

Tagged Variables. Floats, Fixed, Boolean and other.

To get around the fact the Pawn only has one type, Variables can be tagged to emphasize their usage.

Bit manipulation

SetBit( &v, n )
{
	v |= (1 << n);
}

ClearBit( &v, n )
{
	v &= ~(1 << n);
}

ToggleBit( &v, n )
{
	v ^= (1 << n);
}

TestBit( v, n )
{
	return !!(v & (1 << n));
}

Comments

Comming Soon