difference between stock and without stock -
iBots - 18.07.2017
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
}
Re: difference between stock and without stock -
GoldenLion - 18.07.2017
https://sampforum.blast.hk/showthread.php?tid=570635
Re: difference between stock and without stock -
tungki - 18.07.2017
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"
Re: difference between stock and without stock -
ISmokezU - 18.07.2017
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(playerid, name, MAX_PLAYER_NAME);
return name;
}
new tmp[30];
format(tmp sizeof tmp, "Hello %s", PlayerName(playerid));
SendClientMessage(playerid, 1, tmp);
So what would this output?
Re: difference between stock and without stock -
OneDay - 18.07.2017
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
Re: difference between stock and without stock -
aoky - 18.07.2017
PHP код:
PlayerName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
return name;
}
new tmp[30];
format(tmp sizeof tmp, "Hello %s", PlayerName(playerid));
SendClientMessage(playerid, 1, tmp);
It will result in the same thing, literally.
Re: difference between stock and without stock -
Sew_Sumi - 18.07.2017
First reply is the best... Read the information given in that.
Re: difference between stock and without stock -
ISmokezU - 18.07.2017
Quote:
Originally Posted by aoky
PHP код:
PlayerName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
return name;
}
new tmp[30];
format(tmp sizeof tmp, "Hello %s", PlayerName(playerid));
SendClientMessage(playerid, 1, tmp);
It will result in the same thing, literally.
|
Precisely. without the "stock". so his reply was gratuitous.
Re: difference between stock and without stock -
Paulice - 18.07.2017
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.