Different between a stock and a public?
#1

Ey, I script for 2 years now. But still I don't know the different between a Stock and a Public.
I use both of them .

Greetz me.
Reply
#2

I am joining the question.
Reply
#3

im joining to , but i think diference is between braclets [] and ().
Reply
#4

As far as I know(Not a scripter) A public has to be forwarded and has to be used, where as a stock function can be defined in the script but doesn't have to be called.

(As I said, I don't script)
Reply
#5

A stock is a function which can be used for repetitive operations (i.e. strtok, sscanf). Stocks can't be called, they don't have to be forwarded, they can return multiple values, they don't print warnings in the compiler if you don't use them, they're only included in the compiled .amx if you do use them.

As they can't be called by timers, etc. their best use is for returning values of any sort... and if you want a used-to-hell example of a stock, just look at strtok (for commands).
Reply
#6

public are exactly that, public, they can be called from any running script, must be forwarded. public functions can not have default parameters.
stock are for library functions, if you do not call the function in the script it is not compiled.
Reply
#7

Aight I get that part.
But when can I better use a stock instead of a public ?
When I have to return values?
Reply
#8

If you want to use a timer, you have to make it a public.

Functions like 'GetDistanceBetweenPlayers' are usually stocks and you cannot call a stock with a timer or with CallRemoteFunction (I believe).
Reply
#9

Yea ok I know that I cannot use them with timers
I already thought it was something with returning values.
But you also can return values with publics. Anyway Thanks all.
I know more about it now
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)