Implent a function? -
Dayrion - 17.07.2016
Hi'
I'm here to ask you, how to implent a function ? I've the error 004
Код:
error 004: function "OnPlayerKilledPlayer" is not implemented
I know what this mean, I've just to write
PHP код:
OnPlayerKilledPlayer(playerid, deathid)
{
// Codee..
return 1;
}
But this is not the purpose here. I'm looking for implementing a function without creating it like showed before.
Code:
PHP код:
#include <a_samp>
public OnPlayerDeath(playerid, killerid, reason)
{
#if defined OnPlayerKilledPlayer
if(killerid != INVALID_PLAYER_ID) OnPlayerKilledPlayer(playerid, reason);
#endif
return 1;
}
forward OnPlayerKilledPlayer(playerid, deathid);
Thanks for helping.
NB: This is only optimization.
Re: Implent a function? -
Stinged - 17.07.2016
If you don't want to have it in the code (Maybe you're creating an include or something), you need to check if it's defined before forwarding it.
Код:
#if defined OnPlayerKilledPlayer
forward OnPlayerKilledPlayer(playerid, deathid);
#endif
Re: Implent a function? -
iKarim - 17.07.2016
CallLocalFunction
You're directly calling a callback which doesn't exist, so normally compiler raises an error. Using CallLocalFunction is slow, but it wouldn't raise an error if the callback doesn't exist.
Re: Implent a function? -
TheMallard - 17.07.2016
Maybe you should put forward declartion
BEFORE OnPlayerDeath public?
Re: Implent a function? -
Dayrion - 17.07.2016
Quote:
Originally Posted by Stinged
If you don't want to have it in the code (Maybe you're creating an include or something), you need to check if it's defined before forwarding it.
Код:
#if defined OnPlayerKilledPlayer
forward OnPlayerKilledPlayer(playerid, deathid);
#endif
|
Alright, I got it. I didn't think about this way. This is simple optimization exercise but I was stuck. Thanks you.
Quote:
Originally Posted by PawnHunter
CallLocalFunction
You're directly calling a callback which doesn't exist, so normally compiler raises an error. Using CallLocalFunction is slow, but it wouldn't raise an error if the callback doesn't exist.
|
Stinged gave the solution.
Quote:
Originally Posted by TheMallard
Maybe you should put forward declartion BEFORE OnPlayerDeath public?
|
Nothing change about the forward placement, that's why when you declare a public function, usually, you put the forward before.
Re: Implent a function? -
Misiur - 17.07.2016
Erm, isn't this simply because you forwarded a function but forgot to put public in front of it?
#E: Oh, sorry, misread stuff.
Re: Implent a function? -
Dayrion - 17.07.2016
Quote:
Originally Posted by Misiur
Erm, isn't this simply because you forwarded a function but forgot to put public in front of it?
|
No, the function isn't declared so I can't forward it.
Re: Implent a function? -
Mauzen - 17.07.2016
The "#if defined" solution tends to cause problems when working with certain hooking methods and other #define stuff. CallLocalFunction is the way you normally do this, as PawnHunter posted. This wont cause any problems with hooking.