SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 12/04/2015, 10:31 PM   #11
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,378
Reputation: 569
Default Re: Stop the abuse of stock!

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.
__________________
iZN is offline   Reply With Quote
Old 12/04/2015, 10:37 PM   #12
Michael@Belgium
High-roller
 
Michael@Belgium's Avatar
 
Join Date: Dec 2010
Location: Belgium
Posts: 1,770
Reputation: 1001
Default Re: Stop the abuse of stock!

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.
__________________

Need host-tab ? Contact me on discord^

sO aCtIvE
You last visited: 11/01/2018 at 11:21 PM
You last visited: 09/10/2018 at 08:30 PM
Michael@Belgium is offline   Reply With Quote
Old 12/04/2015, 11:14 PM   #13
yugecin
Big Clucker
 
Join Date: Oct 2009
Location: Belgium
Posts: 82
Reputation: 82
Default 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.
__________________
robin_be
yugecin is offline   Reply With Quote
Old 13/04/2015, 12:42 AM   #14
EiresJason
Gangsta
 
Join Date: Mar 2013
Location: Dublin.
Posts: 685
Reputation: 76
Default 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
EiresJason is offline   Reply With Quote
Old 13/04/2015, 01:00 AM   #15
Onfroi
Banned
 
Join Date: Jan 2012
Location: Dallas, Texas
Posts: 1,509
Reputation: 226
Default Re: Stop the abuse of stock!

I thought stock is faster as well, more optimized, it's not?
Onfroi is offline   Reply With Quote
Old 13/04/2015, 02:18 AM   #16
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,758
Reputation: 840
Default Re: Stop the abuse of stock!

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.
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 13/04/2015, 02:48 AM   #17
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,142
Reputation: 445
Default Re: Stop the abuse of stock!

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!
Abagail is offline   Reply With Quote
Old 13/04/2015, 02:59 AM   #18
EiresJason
Gangsta
 
Join Date: Mar 2013
Location: Dublin.
Posts: 685
Reputation: 76
Default Re: Stop the abuse of stock!

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

Last edited by EiresJason; 14/04/2015 at 01:55 AM.
EiresJason is offline   Reply With Quote
Old 13/04/2015, 03:11 AM   #19
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,833
Reputation: 1292
Default Re: Stop the abuse of stock!

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();
Pottus is offline   Reply With Quote
Old 13/04/2015, 03:21 AM   #20
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,142
Reputation: 445
Default Re: Stop the abuse of stock!

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.
Abagail is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
G abuse Cerealguy Scripting Help 3 12/01/2015 03:40 PM
Repair Abuse MBilal Scripting Help 12 30/09/2013 04:03 PM
Pickup abuse.. ThePhill97 Scripting Help 1 23/11/2012 07:14 PM
How to make stock stop a script? ddnbb Scripting Help 12 27/08/2012 02:29 PM
[AJUDA] Stock stock GetVehicleModelID(nome[]) Baigou PortuguÍs/Portuguese 1 09/11/2011 12:21 AM


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


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