SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 13/04/2015, 04:31 PM   #31
S4t3K
Gangsta
 
S4t3K's Avatar
 
Join Date: Jan 2013
Posts: 864
Reputation: 165
Default Re : Stop the abuse of stock!

@Emmet_ : static globals are useful. But only in libraries.

OT : Nice tut. I was aware of it, though never told it to correct someone - I'm maybe guilty or maybe not, not that I answered much helping threads - IMO that was useless since, as someone (sorry to not remember the name) said above, the lambda samp user won't learn from this. Some of them will read, but none of them will learn. Their only point being here is to get their scripting problems solved by someone else.

By the way we're talking about functions, I read somewhere that you could "forward" public functions using the "static" keyword. This way, the public function will be static : if another function with the same name exists in a gamemode where your library is included, it won't create compiling errors.

PHP Code:

// in mylib.inc

static myPublic();
public 
myPublic()
{
      
printf("Called from library");
}

// in gm

#include <mylib>

forward myPublic();
public 
myPublic()
{
      
printf("Called from gamemode");
      return 
1;

__________________
S4t3K is offline   Reply With Quote
Old 14/04/2015, 01:48 AM   #32
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,066
Reputation: 149
Default AW: Stop the abuse of stock!

...it's doesn't matter for the .amx if you write stock in front of a function or not, if you use it.

So...why not
__________________
Kaliber is offline   Reply With Quote
Old 18/04/2015, 12:32 AM   #33
Ahmad45123
Gangsta
 
Ahmad45123's Avatar
 
Join Date: Oct 2013
Location: Egypt
Posts: 828
Reputation: 187
Default Re: AW: Stop the abuse of stock!

Quote:
Originally Posted by Kaliber View Post
...it's doesn't matter for the .amx if you write stock in front of a function or not, if you use it.

So...why not
I don't really know if removing it will affect anything like performance...
But what everyone is trying to say is that everyone are using stock wrong.
__________________

ExtremeStudio

The Best SAMP IDE.
Ahmad45123 is offline   Reply With Quote
Old 18/04/2015, 07:25 AM   #34
Bakr
Gangsta
 
Join Date: Apr 2011
Posts: 975
Reputation: 198
Default Re: Re : Stop the abuse of stock!

Thank you for posting this. It really irks me that people write code when they don't really know what it does.
__________________

Looking for some people to help me with script testing. If you would be interested, send me a PM.

Quote:
Originally Posted by RiChArD_A
Bakr, what have done to you . You don't know me to be saying that I'm lazy. Your fucked ass mom is the only idiot here, ass hole.
Bakr is offline   Reply With Quote
Old 18/04/2015, 07:18 PM   #35
S4t3K
Gangsta
 
S4t3K's Avatar
 
Join Date: Jan 2013
Posts: 864
Reputation: 165
Default Re : Stop the abuse of stock!

@Kaliber : Probably one of the most stupid things I've ever read here.

Indentation also doesn't matter for the amx file. Your whole gamemode is actually one line.
Doing that is thus perfectly acceptable (and will compile fine) :

PHP Code:

main
{printf("My gamemode is loaded !");} public OnPlayerConnect(playerid){if(isBanned(playerid)) Kick(playerid); SendClientMessage(playerid,-1,"Welcome to my server mate !");} public OnPlayerDisconnect(playeridreason){if(reason==1SendClientMessage(playerid,-1"See you soon mate !"); else SendClientMessageToAll(-1"Someone got a problem and got disconnected :(");} 
So...Why not ?

You know that it won't affect the amx file to put spaces, though, you still do it.
It's the same way with stock. It won't affect the amx file whether you put it or not, but if you put it everywhere, you simply forget why this keyword has been made for.
__________________
S4t3K is offline   Reply With Quote
Old 25/04/2015, 01:51 PM   #36
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,066
Reputation: 149
Default AW: Re : Stop the abuse of stock!

Quote:
Originally Posted by S4t3K View Post
you simply forget why this keyword has been made for.
Ahh yes sure...

Seems legit
__________________
Kaliber is offline   Reply With Quote
Old 01/05/2015, 11:16 PM   #37
vannesenn
Gangsta
 
vannesenn's Avatar
 
Join Date: Feb 2011
Posts: 607
Reputation: 15
Default Re: Stop the abuse of stock!

I'm using stock instead public for a whole time, it's that correct? :/
vannesenn is offline   Reply With Quote
Old 02/05/2015, 01:16 AM   #38
ThePhenix
Gangsta
 
ThePhenix's Avatar
 
Join Date: May 2012
Posts: 803
Reputation: 157
Default Re: Stop the abuse of stock!

Thanks for the info.
ThePhenix is offline   Reply With Quote
Old 03/05/2015, 03:07 PM   #39
Jay_
Gangsta
 
Jay_'s Avatar
 
Join Date: Jul 2009
Posts: 654
Reputation: 204
Default Re: Stop the abuse of stock!

There are a couple of points in this topic that I disagree with.

Is there any evidence to suggest the use of stock has any impact on the code or performance whatsoever?

It was highlighted in a previous post that prefixing functions with "stock" is useful for searchability which is an important thing when we have such limited IDE's for PAWN.
Yes, you can add preprocesser defines for "function", but if the use of stock doesn't make a difference, why bother? Also, "function" is a very broad term - what about callbacks or mutator methods?

Quote:
Originally Posted by Vince View Post
  • 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
Perhaps you need to elaborate on the term "internal" here. The static keyword will bind a function/variable to the specific file that it is being declared in (think of it as the private access modifier).
One could argue that in the context of which you're using this term, filterscripts or gamemodes which may consist of many different files would be classed as "internal" as they're not includes.
Jay_ is offline   Reply With Quote
Old 18/05/2015, 01:50 AM   #40
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 929
Reputation: 158
Default Re: Stop the abuse of stock!

I use stock but only in one file normally.
The reason is I have a include with many functions i wrote or some from the useful functions thread.
These are functions that may or may not be used in a gamemode.
Now instead of making a new include for each game mode and picking and hunting only the "stock functions"
i need i just include the same one with every mode.(lazy yes i know)


Also when i start a new mode, i may plan to use most/all the functions in the final release however
impossible to use them all right away. As my mode grows the functions are available to me.(I kinda thought this is what stock was for)
I suppose when something becomes a release it would not be a bad idea
to remove the stock modifier from the include and remove unused functions.

anyhow good insights
thanks.
__________________
If your topic says "REP+", I ignore it.
Jonny5 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 11:55 PM.


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