Stock and public
#1

Well I still can't see the difference between creating a new stock and forwarding a new public. What is it?
Reply
#2

public functions can be called via timer, or CallRemote/LocalFunction.
Stocks however cannot.

So
pawn Код:
SetTimer("Function",1000,false);

stock Function(playeird)
will not work.
pawn Код:
SetTimer("Function",1000,false);

forward Function(playerid);
public Function(playeird)
Will work.

Also, public functions can't return strings, currently.
Reply
#3

If you create a stock function, it's a function which is only defined in your AMX when you use it somewhere, i.e. in a command. These are optimal for functions you're not sure if you'll use, and are a lot more minimal than public functions. Stocks can only be called in the script you're currently using and can't be used in timers.

If you create a public function, it can be called at any time. It will always exist in the AMX, unless you remove it when you compile again. Public functions can be called in timers, across different scripts, through plugins and various other ways. All public functions should be forwarded.
Reply
#4

So why does people still use stock sometimes?
Reply
#5

Stocks are useful for small snippets of code (but not limited to just small snippets) and bits that don't need to be called from other scripts or by timers. People can just use no keyword for their functions, but I personally prefer just using the 'stock' keyword in case I don't use the function.
Reply
#6

Sorry for being kinda dumb, I'm kind of new to scripting but what's the point of creating a stock if you can't call it?
Reply
#7

You can call it, you just can't call it from timers or different scripts.

This wiki page should hopefully clear things up a little for you.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)