11.05.2012, 03:17
(
Последний раз редактировалось SuperViper; 11.05.2012 в 04:17.
)
Introduction
I made this tutorial to show people what the different function types are, when to use them, and what each of them do. I made this tutorial because everybody seemed to be using function types without actually knowing what they do.
Stock Functions
Explanation:
Stocks hide all warnings caused by that function from showing when compiling your script.
Usage:
Stocks shouldn't be used a lot unless you're making functions inside of an include.
Example:
Public Functions
Explanation:
Public functions can be called via CallLocalFunction, CallRemoteFunction, SetTimer, and SetTimerEx. Public functions cannot return strings. You are required to forward a public function ( forward functionName(params or blank) ) or you will receive a warning in the compiler.
Usage:
When creating a timer or a callback in an include, you should use a public function.
Example:
Plain Functions
Explanation:
Plain functions are just normal functions that do everything inside of the function.
Usage:
Plain functions should be used when you don't need to use a stock or a public for what you're trying to do.
Example:
Conclusion
Publics and stocks aren't needed most of the time and you can just use a plain function.
I made this tutorial to show people what the different function types are, when to use them, and what each of them do. I made this tutorial because everybody seemed to be using function types without actually knowing what they do.
Stock Functions
Explanation:
Stocks hide all warnings caused by that function from showing when compiling your script.
Usage:
Stocks shouldn't be used a lot unless you're making functions inside of an include.
Example:
pawn Код:
stock includeName_DoAction(playerid)
{
// do stuff
}
Public Functions
Explanation:
Public functions can be called via CallLocalFunction, CallRemoteFunction, SetTimer, and SetTimerEx. Public functions cannot return strings. You are required to forward a public function ( forward functionName(params or blank) ) or you will receive a warning in the compiler.
Usage:
When creating a timer or a callback in an include, you should use a public function.
Example:
pawn Код:
forward timer1();
public timer1()
{
// do stuff
}
pawn Код:
forward includeName_OnAction(playerid);
if( ... )
{
CallRemoteFunction("includeName_OnAction", "d", playerid);
}
Plain Functions
Explanation:
Plain functions are just normal functions that do everything inside of the function.
Usage:
Plain functions should be used when you don't need to use a stock or a public for what you're trying to do.
Example:
pawn Код:
IsPlayerEnemy(playerid, forplayerid)
{
// do stuff
}
Conclusion
Publics and stocks aren't needed most of the time and you can just use a plain function.