Can someone tell me the difference
#1

i want to know the difference between doing functions in both of this ways

pawn Код:
forward test(playerid);

public test(playerid)
{

}
And this

pawn Код:
stock test(playerid)
{

}
Reply
#2

Just searched this myself.

For public functions:

Код:
A function should be public whenever "the server" must be able to call the function at run time.
For stocks:

Код:
Stocks are a form of function. The only noticeable difference between a stock and a function is that when you don't use a stock, you don't get a warning. Stocks are powerful little tools that allow you to move large repeated bits of code away from the main block, making it easier to edit something that is used in multiple places.

When you compile a script only the stocks which you use in your script are saved, and any you fail to include do not appear in the compiled ".amx", thus increasing efficiency in one way or another. For example, if you have a stock that gave the player a vehicle, but you never use it, when you go to compile the compiler wouldn't bothered including it. This makes it advantageous to have large stock libraries stored in includes, as the script will only "extract" the ones it requires upon compiling.
Hope I helped.
Reply
#3

The main difference between public functions and stock functions is that stock functions are not compiled in the script unless you actually use them in your script, so no warnings telling you that the function is not being used.

From my personal point of view, they can do the same, but they are intended for different usages.
Reply
#4

May i ask for these different uses cuz i see no difference
Reply
#5

Quote:
Originally Posted by Healian
Посмотреть сообщение
May i ask for these different uses cuz i see no difference
For example, stocks are useful when writing libraries : You are stocking functions for an eventual use, if a stock function is used, it will be compiled, if not, it will be discarded from the compiled code.

Public functions are always compiled, no matter if you make use of them or not, wich is why you get a warning when not using them.

__________

In short words :

- Stocks are intended for keeping a list of functions that you will eventually use in the course of development, they can be sorted in libraries (Ex : File manipulation libraries)
- Public functions are used for (almost) all the rest : The actual functions that represent the structure of your code, Callbacks, etc.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)