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)

iZN 12/04/2015 09:31 PM

Re: Stop the abuse of stock!
 
Quote:

Originally Posted by Michael@Belgium (Post 3429367)
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.

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

Re: Stop the abuse of stock!
 
Quote:

Originally Posted by Vince (Post 3429370)
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 (Post 3429371)
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.

yugecin 12/04/2015 10:14 PM

Re: Stop the abuse of stock!
 
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.

EiresJason 12/04/2015 11:42 PM

Re: Stop the abuse of stock!
 
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

Onfroi 13/04/2015 12:00 AM

Re: Stop the abuse of stock!
 
I thought stock is faster as well, more optimized, it's not?

Gammix 13/04/2015 01:18 AM

Re: Stop the abuse of stock!
 
Quote:

Originally Posted by Onfroi (Post 3429479)
I thought stock is faster as well, more optimized, it's not?

No, i think bit slower than a function.

Abagail 13/04/2015 01:48 AM

Re: Stop the abuse of stock!
 
Quote:

Originally Posted by EiresJason (Post 3429475)
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!

EiresJason 13/04/2015 01:59 AM

Re: Stop the abuse of stock!
 
Quote:

Originally Posted by Abagail (Post 3429517)
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 :D

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

Pottus 13/04/2015 02:11 AM

Re: Stop the abuse of stock!
 
Quote:

Originally Posted by Abagail (Post 3429517)
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();

Abagail 13/04/2015 02:21 AM

Re: Stop the abuse of stock!
 
Quote:

Originally Posted by Pottus (Post 3429525)
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.


All times are GMT. The time now is 02:15 AM.

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