31.07.2014, 18:46
(
Последний раз редактировалось Bertie; 01.08.2014 в 15:03.
)
SCRIPTING IN PAWN FOR SA-MP MODIFICATION
VariableWhat is a variable? A variable is basically a bit of memory that stores a value and can be changed on runtime (runtime is when the server is running)
Quoted from Wikipedia:
In computer programming, a variable or scalar is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value.
Quick notes:
1. A value is a piece of stored information that can be manipulated by the computer.
2. A symbolic name or identifier is just a name for a variable which stores a value.
3. When creating a variable you give it a name (a symbolic name or identifier) and a value.
Data type
What is a data type? A data type is a type of variable.
Quoted from Wikipedia:
In computer science and computer programming, a data type or simply is type a classification identifying one of various types of data, such as real, integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored.
Data types in PAWN:
- "Boolean"
pawn Код:
new boolean:myBoolean = true;
pawn Код:
new myInteger = 17;
pawn Код:
new Float:myFloat = 85.567;
pawn Код:
new playername[24] = “Bertie”;
pawn Код:
new myArray[4];
1. A boolean stores two values which are denoted as true and false.
2. An integer stores integral values which are whole numbers.
3. A float stores floating-point values which have potential decimal places
4. A string stores a text.
5. An array stores a collection of values using one variable name.
Function
What is a function? A function is a structure of instructions that perform a specific task when called by the server.
Quoted from Wikipedia:
In computer programming, a subroutine is a sequence of program instructions that perform a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.
In different programming languages a subroutine may be called a procedure, a function, a routine, a method, or a subprogram. The generic term callable unit is sometimes used.
Example of scripting a function:
pawn Код:
forward pName(playerid); // Forwarding the function
public pName(playerid)
{
new playername[24]; // We create a string for storing the text (player's name)
GetPlayerName(playerid, playername, sizeof(playername)); // We use a native function for getting the player's name
return playername;
}
// We created that function to easier get a player name anywhere in the script when called, for example:
public OnPlayerConnect(playerid) // Callback
{
new string[128]; // We create a string for storing the text (message)
format(string, sizeof(string), "%s has connected to the server", pName(playerid)); // We format the string to include another string
SendClientMessageToAll(string, -1); // We use a native to send the message to all players
return 1;
}
What is a native function? A native function is a function that is already implemented into the script by another scripter(s).
Quoted from Wikipedia:
The "native" adjective refers to software or data formats supported by a certain system with minimal computation overhead and additional components.
Example of a native function:
pawn Код:
native SendClientMessage(playerid, color, const message[]);
To be continued.....
Please only give your opinion on what is written so far
Please only give your opinion on what is written so far