Hello, I have question What is the different between this :
local function a()
end
an this :
function b()
end
Is there a different to call them ?
A different to scripts optimization ?
…
Hello, I have question What is the different between this :
local function a()
end
an this :
function b()
end
Is there a different to call them ?
A different to scripts optimization ?
…
It could be wrong or misconstrued but from what I’ve read:
local functions can provide a slight performance increase in the same manner that local variables do being index stored in the stack loaded at compile time versus globals being key/value pairs in globals table that are referenced.
local functions and variables are limited to the scope they are declared in whereas globals can be accessed by any function through a lexically scoped variable.
There are likely other key differences that matter more or less. I’ve adopted a style over time to use local variables and functions as a default and only use globals when scope limitations of local would prevent other parts of the script/resource from working properly. Insofar as calling on your examples above there is no difference, in both cases it’s just:
a()
b()
However if you declaring as local function a() and call it out of lexical scope in your resource it will fail whereas if declared global as function b() is then it can by called out of lexical scope.
Good. That’s good coding practice! Your descriptions and explanations were great, by the way.
Ok so if I understood everything, I can call it in all client side files if it’s a global function
but if it’s a local function, I can only call it in the current file.
That’s it ?
Actually, FiveM scopes resources. So if it’s global, you can call it from any script in the same resource on the same side. So if it’s a global client side function, you can call that function from any script client side in that resource. The exception there is if you make the resource a dependency, or make an export function.
so you mean if a function is declared in client-side script (no matter local or without local) cannot be called in server-side script right?