Scripting Basics NL
From SA-MP
Contents |
Type variabelen
Variabelen zijn ruimtes om data op te slaan. In PAWN zijn de namen van variabelen hoofdletter gevoelig, dit houd in dat een variabele genaamd "lol" anders is dan "loL" en "LOL", daarnaast moeten variabelen altijd beginnen met een letter.
Integer
Dit is het standaard type variabele, deze word gebruikt om hele cijfers in op te slaan. Dit houd dus in dat cijfers met een punt er tussen hier niet in opgeslagen moeten worden.
Voorbeeld
new integer; // Deze manier slaat de waarde 0 op in "integer" vanwege dat dit de standaard waarde is voor een integer.
Mogelijke gebruikswijze
Float
Dit type variablen kan getallen opslaan die 1 of meer decimalen heeft, zoals bijvoorbeeld 1.01, hierbij is het niet mogelijk om een getal op te slaan zonder decimaal.
Voorbeeld
new Float:float = 2.0; // Deze manier maakt de variabele "float" aan en geeft het de waarde 2.0.
Mogelijke gebruikswijze
SetPlayerPos(playerid, float, 2.0, 1400.0);
String
Deze variabele manier slaat één letter of symbool op per cel, de hoeveelheid cellen zal aangegeven moeten worden door middel van een array, hierbij zal 1 extra cell opgetelt moeten worden.
Voorbeelden
string[0] = 'S';
string[1] = 't';
string[2] = 'r';
string[3] = 'i';
string[4] = 'n';
string[5] = 'g';
Meest gebruikte mogelijkheid
Mogelijke gebruikswijze
SendClientMessage(playerid, 0xFFFFFFAA, string);
Boolean
Het variabele type "Boolean" word gebruikt om waar (true) of niet waar (false) in op te slaan, waar staat gelijk aan 1 en niet waar aan 0. Nieuw aangemaakt Booleans zijn automatisch niet waar.
Voorbeelden
Mogelijke gebruikswijze
Array
Arrays are large storage places for data to be stored, they are virtual tables. You can have single dimension arrays and multi dimension arrays. You must create a new float or boolean array the same as you would with a non-arrayed variable by using the predefined tag names (bool:, Float:).
Note that in an array you CANNOT use last row or ligne
One-dimensional array
A one-dimensional array is a single row split into the specified amount of cells.
Example
Possible Use
printf("Random number is: %d", onedimensionalarray[random]); // Uses random number to select a cell.
Two-dimensional array
Two dimensional array allows you to have many collumns and rows.
Example
{3.0, 4.5, 5.76}, // Row number 0
{10.85, 76.34, 23.54}, // Row number 1
{2.32, 10.23, 80.2}, // Row number 2
{6.6666, 45.3, 32.64} // Row number 3
Possible Usage
Tree-dimensional array - Two-dimensional array string
Two-dimensional array string
Conditional
Conditionals allow you to see if data meets conditions then execute code depending on the result. The most common type of conditional would be the if/else conditional, but their are also many others - case, for loop and while loop.
if/else
The if/else conditionals allow you see if a set of data meets a condition by the use of operators and then if the data does meet the condition - execute the code.
Relational Operators
Relational operators are commonly used in if/else statements; they check the relationship between two sets of data before executing code.
| Operator | Meaning | Usage |
|---|---|---|
| == | Left is equal to Right | if(Left == Right) |
| != | Left is not equal to Right | if(Left != Right) |
| > | Left is greater than Right | if(Left > Right) |
| >= | Left is greater than or equal to Right | if(Left >= Right) |
| < | Left is less than Right | if(Left < Right) |
| <= | Left is less than or equal to Right | if(Left <= Right) |
| Operator | Meaning | Usage |
|---|---|---|
| && | AND | if(Left && Right) |
| || | OR | if(Left || Right) |
| ! | NO | if(!Variable) |
| NOR | if(!(Left || Right)) | |
| NAND | if(!(Left && Right)) | |
| XOR | if((Left && !Right)||(!Left && Right)) | |
| NXOR | if(!((Left && !Right)||(!Left && Right))) |
Example
In this example if the conditions between lvalue and rvalue are true it will execute the code. The conditions are if lvalue is greater than rvalue...
This article is a stub. You can help SA-MP by expanding it.
