Stock and public - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Stock and public (
/showthread.php?tid=335885)
Stock and public -
Tomer!.$ - 20.04.2012
Well I still can't see the difference between creating a new stock and forwarding a new public. What is it?
Re: Stock and public -
ReneG - 20.04.2012
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.
Re: Stock and public -
Calgon - 20.04.2012
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.
Re : Stock and public -
Tomer!.$ - 20.04.2012
So why does people still use stock sometimes?
Re: Stock and public -
Calgon - 20.04.2012
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.
Re : Stock and public -
Tomer!.$ - 20.04.2012
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?
Re: Stock and public -
Calgon - 20.04.2012
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.