[Tutorial] Stop the abuse of stock!
#1

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.
Reply
#2

Nice, didn't knew
Reply
#3

lool
Reply
#4

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.
Reply
#5

Stop stock abuse, NOW!

Sign the petition:
stopstockkeywordabuseinpawnscripts.com
Reply
#6

Amen!
Reply
#7

Why isn't this a sticky yet
Reply
#8

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
View Post
No, you're writing a function!
stock angryface(jpg) {}
Reply
#9

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.
Reply
#10

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.
Reply
#11

Quote:
Originally Posted by Michael@Belgium
View Post
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.
You got him all wrong, he basically meant, you could simply do like this:

pawn Code:
whateverFunction(with, whatever, parameters = 1) {}
So basically, you're not required to use "stock", you could leave it naked or the other ways of using "static" keyword if it's used locally/internally.
Reply
#12

Quote:
Originally Posted by Vince
View Post
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.
Quote:
Originally Posted by iZN
View Post
You got him all wrong, he basically meant, you could simply do like this:

pawn Code:
whateverFunction(with, whatever, parameters = 1) {}
So basically, you're not required to use "stock", you could leave it naked or the other ways of using "static" keyword if it's used locally/internally.
Alright, i deserve -rep now tbh. I always learned to use stock because those damn tutorials ..
And yes Vince, i did read. But too fast.
Reply
#13

I always wondered why people would put stock before every function. I would think most scripters know what they're doing, or perhaps "because it looks pretty with a keyword" (the stock keyword is ugly imho).
Just write functions and if you don't use one, the compiler will kindly remember you and then refactor your code instead of filling it with stock modifiers.
Reply
#14

I find it much easier putting 'stock' in front of a function to find a particular function though.

Like, I want to edit the function (for example)
pawn Code:
SetPlayerLevel(playerid, level) {
   //..code
}
But let's say I actually call it 15 times in my script. Pressing CTRL+F and searching for "SetPlayerLevel" may need to me to skip past a good few calls before I get to the actual function, but having..
pawn Code:
stock SetPlayerLevel(playerid, level) {
   //..code
}
lets me just search for "k SetPlayerLevel" and I'm at it right away.

If that makes sense xD
Reply
#15

I thought stock is faster as well, more optimized, it's not?
Reply
#16

Quote:
Originally Posted by Onfroi
View Post
I thought stock is faster as well, more optimized, it's not?
No, i think bit slower than a function.
Reply
#17

Quote:
Originally Posted by EiresJason
View Post
I find it much easier putting 'stock' in front of a function to find a particular function though.

Like, I want to edit the function (for example)
pawn Code:
SetPlayerLevel(playerid, level) {
   //..code
}
But let's say I actually call it 15 times in my script. Pressing CTRL+F and searching for "SetPlayerLevel" may need to me to skip past a good few calls before I get to the actual function, but having..
pawn Code:
stock SetPlayerLevel(playerid, level) {
   //..code
}
lets me just search for "k SetPlayerLevel" and I'm at it right away.

If that makes sense xD
This isn't a good enough reason to use stock, you can even simply do something such as this:
pawn Code:
#define SetPlayerLevelEx FUNC_SetPlayerLevel
pawn Code:
FUNC_SetPlayerLevel(playerid, level) {
   // .. code
Then you can just search for "FUNC_Functionname", - calling the function throughout the script as "SetPlayerLevelEx".

If it gets on your nerves so much try this or another method, but as I said this is NOT A GOOD REASON TO USE STOCK!
Reply
#18

Quote:
Originally Posted by Abagail
View Post
This isn't a good enough reason to use stock, you can even simply do something such as this:
pawn Code:
#define SetPlayerLevelEx FUNC_SetPlayerLevel
pawn Code:
FUNC_SetPlayerLevel(playerid, level) {
   // .. code
Then you can just search for "FUNC_Functionname", - calling the function throughout the script as "SetPlayerLevelEx".

If it gets on your nerves so much try this or another method, but as I said this is NOT A GOOD REASON TO USE STOCK!
Could you explain why it isn't good enough though? At the moment though , when I'm going to compile my GM, I just replace all instances of "stock " with "" so it removes the stock modifier at compile time and I have the easy search functionality when I'm scripting.

Thanks for the suggestion but it doesn't seem reasonable to do that for every single function I use

EDIT: So yeah.. it literally makes no difference? XD
Reply
#19

Quote:
Originally Posted by Abagail
View Post
This isn't a good enough reason to use stock, you can even simply do something such as this:
pawn Code:
#define SetPlayerLevelEx FUNC_SetPlayerLevel
pawn Code:
FUNC_SetPlayerLevel(playerid, level) {
   // .. code
Then you can just search for "FUNC_Functionname", - calling the function throughout the script as "SetPlayerLevelEx".

If it gets on your nerves so much try this or another method, but as I said this is NOT A GOOD REASON TO USE STOCK!
Why even do that? Just put #define Function at the top of your script then.

Ex.
Function Test();
Reply
#20

Quote:
Originally Posted by Pottus
View Post
Why even do that? Just put #define Function at the top of your script then.

Ex.
Function Test();
What do you mean by #define function? What I am saying is he should look into internally using a function name for the actual function, while within the .pwn file using another one for within the script(calling the function), however in compilation, everything will be the same.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)