23.04.2015, 21:19
(
Last edited by Buthers; 24/04/2015 at 08:31 PM.
)
Pawn-Tutorial n°2 :
Directives #if, #else, #elseif, #endif and #error
In this tutorial I will teach you how to handle the #if directive, accompanied #else directives #elseif, and #endif #error without which the directive would have no purpose.
We will also mention the #define directive, I invite you to read my previous tutorial: https://sampforum.blast.hk/showthread.php?tid=571802 !
What is the directive #if ?
This directive allows you to check a very specific condition, it is also a preprocessor in the Pawn.
What is the directive #else ?
This directive is in contradiction with the #if directive, it helps to check if the outcome is not accurate.
What is the directive #elseif ?
This directive is useful if you want to mention several contradictions in your checking. We will study it in more detail in a moment.
What is the directive #endif ?
This directive will be fully used to declare the end of our audit. We will study it in more detail in a moment.
What is the directive #error ?
This directive will be used to declare a compilation error in our script. It is very useful if you want to perform specific checks.
We will study it in more detail in a moment.
Use the directives
Usually you check a condition using if and else like this:
Thanks to our directives #if #else #error and #endif , here is our new code:
It is obvious that you will not do all your checks using these directives. I advise you to use the top of your script to check fixed and precise information.
Now about the directive #elseif. We will use it to check other information:
The advantage of using #elseif not #else each contradiction is already normal but above we use to perform several contradictions in the same verification .
This tutorial was, again, very short but it's really the principle of these directives, verification. I would say that the directive #error is a result after checking, but you understand how it is used. Hoping you have cleared again, do not hesitate to inform me of my tutorial erroneous information. If necessary, I am available for MP.
Good day!
Directives #if, #else, #elseif, #endif and #error
In this tutorial I will teach you how to handle the #if directive, accompanied #else directives #elseif, and #endif #error without which the directive would have no purpose.
We will also mention the #define directive, I invite you to read my previous tutorial: https://sampforum.blast.hk/showthread.php?tid=571802 !
What is the directive #if ?
This directive allows you to check a very specific condition, it is also a preprocessor in the Pawn.
What is the directive #else ?
This directive is in contradiction with the #if directive, it helps to check if the outcome is not accurate.
What is the directive #elseif ?
This directive is useful if you want to mention several contradictions in your checking. We will study it in more detail in a moment.
What is the directive #endif ?
This directive will be fully used to declare the end of our audit. We will study it in more detail in a moment.
What is the directive #error ?
This directive will be used to declare a compilation error in our script. It is very useful if you want to perform specific checks.
We will study it in more detail in a moment.
Use the directives
Usually you check a condition using if and else like this:
PHP Code:
#define MyInfo 3
if(MyInfo >= 3)
{
print("MyInfo enough !");
}
else
{
print("MyInfo inadequate !");
}
PHP Code:
#define MyInfo 3
#if MyInfo >= 3
#error MonInfo enough !
#else
#error MonInfo inadequate !
#endif
Now about the directive #elseif. We will use it to check other information:
PHP Code:
#define MyInfo 3
#if MyInfo >= 3
#error MyInfo enough !
#elseif MyInfo < 3
#error MyInfo inadequate !
#endif
This tutorial was, again, very short but it's really the principle of these directives, verification. I would say that the directive #error is a result after checking, but you understand how it is used. Hoping you have cleared again, do not hesitate to inform me of my tutorial erroneous information. If necessary, I am available for MP.
Good day!