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:26 AM   #1
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,952
Reputation: 2651
Default 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.
__________________

Last edited by Vince; 07/06/2016 at 01:26 PM. Reason: Some typos
Vince is offline   Reply With Quote
Old 12/04/2015, 11:12 AM   #2
Glossy42O
High-roller
 
Join Date: Oct 2014
Location: in my house
Posts: 1,851
Reputation: 231
Default Re: Stop the abuse of stock!

Nice, didn't knew
Glossy42O is offline   Reply With Quote
Old 12/04/2015, 11:14 AM   #3
FernandoLight
Huge Clucker
 
FernandoLight's Avatar
 
Join Date: Feb 2015
Location: Error: 404
Posts: 319
Reputation: 40
Default Re: Stop the abuse of stock!

lool
__________________
I don't drink to get drunk.
FernandoLight is offline   Reply With Quote
Old 12/04/2015, 01:04 PM   #4
Emmet_
Guest
 
Posts: n/a
Default 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.
  Reply With Quote
Old 12/04/2015, 01:05 PM   #5
Mellnik
Gangsta
 
Mellnik's Avatar
 
Join Date: Dec 2011
Location: Paradise Falls, CAℕADA
Posts: 795
Reputation: 369
Default AW: Stop the abuse of stock!

Stop stock abuse, NOW!

Sign the petition:
stopstockkeywordabuseinpawnscripts.com
Mellnik is offline   Reply With Quote
Old 12/04/2015, 05:12 PM   #6
Patrick
Guest
 
Posts: n/a
Default Re: Stop the abuse of stock!

Amen!
  Reply With Quote
Old 12/04/2015, 07:06 PM   #7
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,410
Reputation: 439
Default Re: Stop the abuse of stock!

Why isn't this a sticky yet
Abagail is offline   Reply With Quote
Old 12/04/2015, 10:17 PM   #8
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,441
Reputation: 569
Default 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 View Post
No, you're writing a function!
stock angryface(jpg) {}
__________________
iZN is offline   Reply With Quote
Old 12/04/2015, 10:25 PM   #9
Michael@Belgium
High-roller
 
Michael@Belgium's Avatar
 
Join Date: Dec 2010
Location: Belgium
Posts: 3,027
Reputation: 1001
Default 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.
__________________
Mah Github. - Need host-tab ? Contact me on discord: michaelbelgium#2759

sO aCtIvE
You last visited: 11/01/2018 at 11:21 PM
Michael@Belgium is offline   Reply With Quote
Old 12/04/2015, 10:30 PM   #10
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,952
Reputation: 2651
Default 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.
__________________
Vince 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 04:51 AM.


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