SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Tutorials (https://forum.sa-mp.com/forumdisplay.php?f=70)
-   -   [Tutorial] Stop the abuse of stock! (https://forum.sa-mp.com/showthread.php?t=570635)

Vince 12/04/2015 09:26 AM

Stop the abuse of stock!
 
What is stock?
The stock keyword, like const, is a modifier that tells the compiler to hide a variable or a function if it is not used. Contrary to popular believe in the SA-MP community, stock is not a requirement. Functions do not require a special keyword in Pawn. The word "stock" is not interchangeable with the word "function" either.

Quote:

Originally Posted by random scripting help topic
Hi, I'm writing this stock ...

No, you're writing a function!

When to use stock?
  • I am writing a gamemode.
    • You don't need the stock keyword!
  • I am writing a filterscript.
    • You don't need the stock keyword!
  • I am writing an include.
    • Is the function or variable required to be used in a gamemode or filterscript? If yes, do not use the stock keyword. Do not use any keyword at all.
    • Is the function or variable for internal use only? If yes, use static.
    • Is the function or variable for internal use only, but is there a chance that it may not be used (conditional compiling)? If yes, use static stock
    • If none of the above are met, only then is it appropriate to use stock.

Removing the stock modifier from ALL functions in your gamemode or filterscript is a good way to start. If you receive a few "symbol is never used" warnings after doing so then that means your gamemode is cluttered. It means you have functions which do nothing but waste your scroll wheel. Consider removing those functions or move them to an appropriate include file.

Glossy42O 12/04/2015 10:12 AM

Re: Stop the abuse of stock!
 
Nice, didn't knew:o

FernandoLight 12/04/2015 10:14 AM

Re: Stop the abuse of stock!
 
lool :D

Emmet_ 12/04/2015 12:04 PM

Re: Stop the abuse of stock!
 
Nicely written. Hopefully people can understand that "stock" is not a keyword for "function". I used to spam it in my scripts myself, so I am guilty of doing this. I read over the documentation again and came to a conclusion that I don't even need it!

I guess you could say the same thing for global static variables in a gamemode - it's not needed.

Mellnik 12/04/2015 12:05 PM

AW: Stop the abuse of stock!
 
Stop stock abuse, NOW!

Sign the petition:
stopstockkeywordabuseinpawnscripts.com

Patrick 12/04/2015 04:12 PM

Re: Stop the abuse of stock!
 
Amen!

Abagail 12/04/2015 06:06 PM

Re: Stop the abuse of stock!
 
Why isn't this a sticky yet

iZN 12/04/2015 09:17 PM

Re: Stop the abuse of stock!
 
They STILL won't understand the true meaning of that keyword. I stopped bothering with the current community members since most of them are not learning, they're on Scripting Help board to get an quick answer, and resolve their issues without even looking what that answer holds.

Nice of you to actually post something like that, good piece of advice.

Quote:

Originally Posted by Vince (Post 3428616)
No, you're writing a function! >:(

stock angryface(jpg) {}

Michael@Belgium 12/04/2015 09:25 PM

Re: Stop the abuse of stock!
 
I like to use stock, it's short to write and easy to use. Don't tell me what to do. ;) If it works .. it works.
So you're basicly saying to always write publics and forward them ? I don't like to type much.

Vince 12/04/2015 09:30 PM

Re: Stop the abuse of stock!
 
Did you actually read what I wrote? Stock is not a requirement. It is merely a modifier.

pawn Code:
myFunction(parameter)
{
    printf("the parameter is %d", parameter);
}

This works. Nothing else required.


All times are GMT. The time now is 10:30 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.