Direct function call vs CallLocalFunction
#1

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?
Reply
#2

Any tips?
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)