Direct function call vs CallLocalFunction - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Direct function call vs CallLocalFunction (
/showthread.php?tid=403758)
Direct function call vs CallLocalFunction -
Gryphus One - 31.12.2012
Hi, when I'm working on a gamemode or filterscript and I have a certain function (for example a custom one), I have noticed that there are at least two ways of calling it: one of them is to call that function directly, and the other is by CallLocalFunction. For example, imagine that I have a custom function to give players some weapons upon spawning:
pawn Код:
forward GiveSpawnWeapons(playerid);
public GiveSpawnWeapons(playerid)
{
GivePlayerWeapon(playerid, 24, 500);
GivePlayerWeapon(playerid, 26, 500);
GivePlayerWeapon(playerid, 28, 500);
GivePlayerWeapon(playerid, 31, 500);
return 1;
}
If I'm going to call this custom function in OnPlayerSpawn, this is the first of the two mentioned ways:
pawn Код:
public OnPlayerSpawn(playerid)
{
GiveSpawnWeapons(playerid);
return 1;
}
And this is the second one:
pawn Код:
public OnPlayerSpawn(playerid)
{
CallLocalFunction("GiveSpawnWeapons", "i", playerid);
return 1;
}
So, what are the differences between one and the other? in what cases should I use one method over the other?
Respuesta: Direct function call vs CallLocalFunction -
Gryphus One - 01.01.2013
Any tips?
AW: Direct function call vs CallLocalFunction -
IPrototypeI - 02.01.2013
You can save memory if you use CallLocalFunction or CallRemoteFunction
then to write everytime new publics.
If you want to use a function every where around your gamemode for example in filterscripts or somewhere
then use this or if you want to hook functions.
But if you use this only one time so you don't need CallLocalFunction or CallRemoteFunction.
And i don't know it really but i think to hook callbacks to call a code is faster than to write a public
and let it called in the callback.