difference between stock and without stock
#1

I have searched for the difference between defining a function without using stock and with using stock, and i cant manage to get an answer, 1.What is the difference between defining a function like this:
pawn Код:
stock Example(playerid)
{
//code
}
and this:
pawn Код:
Example(playerid)
{
//code
}
2.what is the difference between :
pawn Код:
forward Example(playerid);
public Example(playerid)
{
//code
}
and using stock:
pawn Код:
stock Example(playerid)
{
//code
}
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=570635
Reply
#3

if youre using stock you can call it when you need it for example
pawn Код:
stock PlayerName(playerid)
{
      new name[MAX_PLAYER_NAME];
      GetPlayerName(playerid, name, MAX_PLAYER_NAME);
      return name;
}
and then call it without writing the code again
pawn Код:
new SzString[128]
format(SzString, sizeof(SzString), "Hello %s", PlayerName(playerid));
SendClientMessage(playerid, 1, SzString);
which will return Hello "Your Name"
Reply
#4

Quote:
Originally Posted by tungki
Посмотреть сообщение
if youre using stock you can call it when you need it for example
pawn Код:
stock PlayerName(playerid)
{
      new name[MAX_PLAYER_NAME];
      GetPlayerName(playerid, name, MAX_PLAYER_NAME);
      return name;
}
and then call it without writing the code again
pawn Код:
new SzString[128]
format(SzString, sizeof(SzString), "Hello %s", PlayerName(playerid));
SendClientMessage(playerid, 1, SzString);
which will return Hello "Your Name"
PHP код:
PlayerName(playerid)
{
      new 
name[MAX_PLAYER_NAME];
      
GetPlayerName(playeridnameMAX_PLAYER_NAME);
      return 
name;
}
new 
tmp[30];
format(tmp sizeof tmp"Hello %s"PlayerName(playerid));
SendClientMessage(playerid1tmp); 
So what would this output?
Reply
#5

Quote:
Originally Posted by tungki
Посмотреть сообщение
if youre using stock you can call it when you need it for example
pawn Код:
stock PlayerName(playerid)
{
      new name[MAX_PLAYER_NAME];
      GetPlayerName(playerid, name, MAX_PLAYER_NAME);
      return name;
}
and then call it without writing the code again
pawn Код:
new SzString[128]
format(SzString, sizeof(SzString), "Hello %s", PlayerName(playerid));
SendClientMessage(playerid, 1, SzString);
which will return Hello "Your Name"
you do not want stock
Reply
#6

PHP код:
PlayerName(playerid

      new 
name[MAX_PLAYER_NAME]; 
      
GetPlayerName(playeridnameMAX_PLAYER_NAME); 
      return 
name


new 
tmp[30]; 
format(tmp sizeof tmp"Hello %s"PlayerName(playerid)); 
SendClientMessage(playerid1tmp); 
It will result in the same thing, literally.
Reply
#7

First reply is the best... Read the information given in that.
Reply
#8

Quote:
Originally Posted by aoky
Посмотреть сообщение
PHP код:
PlayerName(playerid

      new 
name[MAX_PLAYER_NAME]; 
      
GetPlayerName(playeridnameMAX_PLAYER_NAME); 
      return 
name

new 
tmp[30]; 
format(tmp sizeof tmp"Hello %s"PlayerName(playerid)); 
SendClientMessage(playerid1tmp); 
It will result in the same thing, literally.
Precisely. without the "stock". so his reply was gratuitous.
Reply
#9

Firstly, adding the keyword stock to a function does not make it a stock like most people refer it to as. It can be called a stock function, but that does not eliminate the fact that it's still simply a function. The keyword can also be used with variables for example; however, I'll use functions as a sample in the following:

1. The only difference is that the stock function will lack (won't be added) from the .amx file if the function is never used.

2. Public functions are basically callbacks (if you want to see it that way). The major difference between a public function and a stock function is that public functions can be called using CallLocal/RemoteFunction, setting timers, or in other words, while in run time. Stock functions can't.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)