Pawn from Scratch? Is it really possible to write your own server plugin Week 2
About this content

Week 2: Functions and arrays
- Functions
- What functions are and why they are needed
- How to declare and call functions
- Function return values
Example of working with functions:
main()
{
new result = add(2, 3);
print(result);
}
add(num1, num2)
{
new sum = num1 + num2;
return sum;
}
Explanation:
add()- declaration of a function with two argumentsnew sum- declaration of a variable inside a functionreturn- keyword for returning a value from a function
- Arrays
- What arrays are and how they work
- How to declare and use arrays
Example of working with arrays:
main()
{
new array[5]; // Объявляем массив из 5 элементов
for(new i = 0; i < sizeof(array); i++) // Заполняем массив значениями
{
array[i] = i + 1;
}
print("Array before changes:");
for(new i = 0; i < sizeof(array); i++) // Display the array values before changes
{
print(array[i]);
}
array[2] = 10; // Change the value of the array element with index 2
print("Array after changes:");
for(new i = 0; i < sizeof(array); i++) // Display the array values after changes
{
print(array[i]);
}
}
Explanation:
new array[5]- declaration of an array with 5 elementsfor(new i = 0; i < sizeof(array); i++)- loop for filling and displaying array valuesarray[i] = i + 1- assigning a value to the array element with index iarray[2] = 10- changing the value of the array element with index 2
- Strings
- What strings are and how they work
- How to declare and use strings
Example of working with strings:
main()
{
new str[50] = "Hello, world!"; // Объявляем строку и присваиваем ей значение
print(str); // Выводим строку на экран
format(str, sizeof(str), "Значение числа PI: %.2f", 3.14); // Форматируем строку с помощью функции format()
print(str); // Выводим отформатированную строку на экран
}
Explanation:
new str[50]- declaration of a string and allocation of 50 characters for it






Comments (0)