What is the function, stock?
#1

Yeah, so basically, my downloaded gm script has lots of stock in it, and I cant edit it without knowing what it is.
Sorry, but my shrunken brain doesn't completely understand the definition of stock in the SA-MP wiki. So can anyone please explain it to me in a simple/short way?
Reply
#2

stock is a method. completes code that you have inside the stock. Place the name of the stock in a certain place in your code. It then does the code you have in the stock.

*Sorry, my english is bad :P
Reply
#3

Stock is a keyword that tells the compiler to skip or leave out whatever has the keyword included to it (as if it never existed in the source code), that's if it isn't being used anywhere.

Using stock while creating a function doesn't make it a "stock", it's still a function. Though, you can also call it a "stock function".
Reply
#4

Quote:
Originally Posted by SickAttack
View Post
Stock is a keyword that tells the compiler to skip or leave out whatever has the keyword included to it (as if it never existed in the source code), that's if it isn't being used anywhere.

Using stock while creating a function doesn't make it a "stock", it's still a function. Though, you can also call it a "stock function".
Can you give me an example on what is it used for?
Reply
#5

https://sampwiki.blast.hk/wiki/Function
https://sampforum.blast.hk/showthread.php?tid=341545
Reply
#6

FreAkeD, As I said, I'm having a hard time understanding the definition of stock in the samp wiki. However, the second link is what I'm looking for, Thank you!
Reply
#7

Quote:
Originally Posted by Gorgeousmaniac
View Post
Can you give me an example on what is it used for?
I'm not quite sure why the explanation wasn't enough, but...

Let's say we have this function:
pawn Code:
stock Function(a)
{
    if(a)
    {
        return 1;
    }
    return 0;
}
If I use the function in OnPlayerConnect:
pawn Code:
Function(0);
The function will be added to the .amx file.

If the function isn't used and has stock, it won't be added to the .amx file and it won't give you a warning. It will only exist in the source code (.pwn).

If the function is like below (without stock) and isn't used, instead:
pawn Code:
Function(a)
{
    if(a)
    {
        return 1;
    }
    return 0;
}
You'll get a warning.

If it is used, you won't get a warning.

- Stock makes things that use it lack from the compiled source.
Reply
#8

Quote:
Originally Posted by SickAttack
View Post
I'm not quite sure why the explanation wasn't enough, but...

Let's say we have this function:
pawn Code:
stock Function(a)
{
    if(a)
    {
        return 1;
    }
    return 0;
}
If I use the function in OnPlayerConnect:
pawn Code:
Function(0);
The function will be added to the .amx file.

If the function isn't used and has stock, it won't be added to the .amx file and it won't give you a warning. It will only exist in the source code (.pwn).

If the function is like below (without stock) and isn't used, instead:
pawn Code:
Function(a)
{
    if(a)
    {
        return 1;
    }
    return 0;
}
You'll get a warning.

If it is used, you won't get a warning.

- Stock makes things that use it lack from the compiled source.
I get it now! Thank you SickAttack!
Reply
#9

That doesn't provide an example on what it's used for (and when you need it). This is a better link.

You should only use the stock keyword when you're writing an include for other people to use, in which they can use your functions but aren't required to.
Reply
#10

Quote:
Originally Posted by Hiddos
View Post
That doesn't provide an example on what it's used for (and when you need it). This is a better link.

You should only use the stock keyword when you're writing an include for other people to use, in which they can use your functions but aren't required to.
Negative. It's completely fine to use it while creating functions => stock functions.

It also has other uses than just that one.
Reply
#11

Honestly, the stop the abuse of stock topic is not worthy. It doesn't matter if you keep a function/variable as a stock or not.

The advantage of not using stock is that the compiler warns you if you forget to call the function whereas with stock, the compiler ignores that function (removes it from the code and doesn't even tell you).
Reply
#12

Why put something in a script if you're never going to use it? Stocks should really only belong in includes.
Reply
#13

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Why put something in a script if you're never going to use it? Stocks should really only belong in includes.
If it doesn't hurt, then let it be.

I just use it for accessibility, I don't tend to leave functions (which will lack from the source code when compiled) in a script that won't be used. I don't want to switch to using a define as using stock is more convenient.
Reply
#14

Sure, but it just goes along the same principles as using #pragma tabsize 0 to remove loose indentation warnings.

Using stock where unnecessary just promotes laziness, in my opinion.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)