CallLocalFunction useless
#1

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

I didn't think about that, thanks.
Reply
#3

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)