CallLocalFunction useless - 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)
+---- Forum: Discussion (
https://sampforum.blast.hk/forumdisplay.php?fid=84)
+---- Thread: CallLocalFunction useless (
/showthread.php?tid=569328)
CallLocalFunction useless -
CalvinC - 29.03.2015
Hello.
Is there any use for
CallLocalFunction?
If you don't know, it's used to call public functions within your script, here's an example:
pawn Code:
public SendRandomMessage(playerid)
{
switch(random(2))
{
case 0: SendClientMessage(playerid, -1, "Msg1");
case 1: SendClientMessage(playerid, -1, "Msg2");
}
return 1;
}
CMD:randommessage(playerid)
{
CallLocalFunction("SendRandomMessage", "i", playerid);
return 1;
}
But the thing is, you can also use this:
pawn Code:
CMD:randommessage(playerid)
{
SendRandomMessage(playerid);
return 1;
}
We'll call this "plain" CallLocalFunction.
And using this method works for both plain and public functions, while CallLocalFunction only works for public functions.
So what's CallLocalFunction for? Is it just completely useless, or is there something it can do which the "plain" CallLocalFunction can't?
Re: CallLocalFunction useless -
CalvinC - 29.03.2015
I didn't think about that, thanks.
Re: CallLocalFunction useless -
Abagail - 29.03.2015
Basically as Y_Less said; you can't call a function directly by a string during run-time; however using CallLocalFunction allows this. It also won't return an error if the function isn't called whereas a direct function call will return an undefined symbol error.
Re: CallLocalFunction useless -
theYiin - 12.06.2015
Everything user Abagail said, PLUS you can create custom callbacks with y_hooks, and call all hooked versions of your custom callback with CallLocalFunction. You can do the same with CallRemoteFunction to affect other loaded scripts too, but if callback and its hooks are used only in one script, CallLocalFunction is bit faster.