SA-MP Forums Archive
What are the advantages of using 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: What are the advantages of using CallLocalFunction (/showthread.php?tid=620671)



What are the advantages of using CallLocalFunction - NeXoR - 01.11.2016

Heya, I have noticed the function CallLocalFunction a few times lately and I didn't really get it's usage...
I mean like, what's the difference between this:
PHP код:
CallLocalFunction("RandomFunc""i"playerid); 
to this:
PHP код:
RandomFunc(playerid); 
And so on


Re: What are the advantages of using CallLocalFunction - Jefff - 01.11.2016

Second is faster and thats all


Re: What are the advantages of using CallLocalFunction - Stinged - 01.11.2016

The second one is a lot faster, but you have to know the function's name, and if it exists (You can use #if to check that, but you still have to know the name)

One of the important uses of CallLocalFunction is in command processing, since it calls a function with this format:
cmd_%s(playerid, params[]) *%s = command name

Since the player enters the command name, you replace %s with what they enter (using format, or some other method of processing), and then you use CallLocalFunction.


Re: What are the advantages of using CallLocalFunction - NeXoR - 01.11.2016

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Second is faster and thats all
Second way is faster ?
Than why should anyone ever use this function ? because I see many use it

EDIT
Quote:
Originally Posted by Stinged
Посмотреть сообщение
The second one is a lot faster, but you have to know the function's name, and if it exists (You can use #if to check that, but you still have to know the name)

One of the important uses of CallLocalFunction is in command processing, since it calls a function with this format:
cmd_%s(playerid, params[]) *%s = command name

Since the player enters the command name, you replace %s with what they enter (using format, or some other method of processing), and then you use CallLocalFunction.
Now I get it, thanks


Re: What are the advantages of using CallLocalFunction - Spmn - 01.11.2016

Because:
1) you're using old includes that used CallLocalFunction for hooking
2) script needs to call a function whose name is unknown at compile-time; eg most command processors (look up zcmd source; it's simpler to understand reading a piece of code)


Re: What are the advantages of using CallLocalFunction - SickAttack - 01.11.2016

The second way is a lot faster than the first one, but that's not really relevant to why CallLocalFunction and CallRemoteFunction exists.

If you don't know the name of the function to execute (that being not directly inputting the name of the function during compile-time), then there's no way you're going to manage to call the function using the second way. That's where CallLocalFunction and CallRemoteFunction comes in, they can execute functions even during run-time. Not to mention that you won't be able to call a function inside a filterscript (for example) by using the second way. That's where CallRemoteFunction comes in.


Re: What are the advantages of using CallLocalFunction - NeXoR - 01.11.2016

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
The second way is a lot faster than the first one, but that's not really relevant to why CallLocalFunction and CallRemoteFunction exists.

If you don't know the name of the function to execute (that being not directly inputting the name of the function during compile-time), then there's no way you're going to manage to call the function using the second way. That's where CallLocalFunction and CallRemoteFunction comes in, they can execute functions even during run-time. Not to mention that you won't be able to call a function inside a filterscript (for example) by using the second way. That's where CallRemoteFunction comes in.
Already understood it from Sting, thanks anyways.