Using @ to declare public functions -
Vince - 06.09.2011
Well, first of all this is not really a tutorial, but rather some useful information that I discovered recently. It involves using the @ symbol to declare public functions.
For example, suppose you have this public function:
pawn Код:
forward CallTimer(playerid);
public CallTimer(playerid)
{
// unimportant stuff
}
Now, we can declare this function in a different way using the @ symbol;
pawn Код:
forward @CallTimer(playerid);
@CallTimer(playerid)
{
// unimportant stuff
}
The difference herein is that the @ symbol is now part of the function name (as seen in the forward declaration), while still declaring that function as public and without the need of the 'public' keyword. To call the function via SetTimer/Ex or CallLocal/RemoteFunction you need to include the @ symbol in there too. Example:
pawn Код:
SetTimerEx("@CallTimer", 10000, false, "d", playerid);
The main advantage of using this method is that the actual function name becomes available again for you to use for other function- or even variable names; for example you can have this setup which won't give an error:
pawn Код:
@CallTimer(playerid)
{
// unimportant stuff
}
stock CallTimer(/* params */)
{
// more stuff
}
Whereas
pawn Код:
public CallTimer(playerid)
{
// unimportant stuff
}
stock CallTimer(/* params */)
{
// more stuff
}
WILL give an error (error 021: symbol already defined).
Important Note: This method will not work for the default SA-MP callbacks (ex. OnPlayerConnect) for the reasons stated above!
Re: Using @ to declare public functions -
[MG]Dimi - 06.09.2011
Nice. Thanks, will help.
Re: Using @ to declare public functions -
=WoR=G4M3Ov3r - 06.09.2011
Nice work, you just saved "Scripting Discussions" from massive spamming, hope people will search find this, before they start posting all over the forums.
Oh who am i kidding, that'll never happen.
Good work again.
Re: Using @ to declare public functions -
Jantjuh - 06.09.2011
Nice! Sure gonna use this instead of "public" :P
Looks way coolahr :P
Re: Using @ to declare public functions -
Davz*|*Criss - 09.09.2011
Nice work, vince!
Re: Using @ to declare public functions -
Lorenc_ - 09.09.2011
Interesting read, '@' just replaces the keyword 'public'? I saw some of this stuff in ******'s source. Nice information stated inside. I myself found this handy