Whats the difference between the function This and These and which one of them is faster / better for optimized scripts?
local This = function()
print('hi')
end
local function These()
print('hi')
end
This()
These()
Whats the difference between the function This and These and which one of them is faster / better for optimized scripts?
local This = function()
print('hi')
end
local function These()
print('hi')
end
This()
These()
They are different. In terms of how they are defined and can be called.
In example below "a" cannot call its self within function "a" because is still being defined
In example below "b" can call its self since "b" was defined.
How exactly does this work?
local function b() b() end means local b; b = function() b() end to the interpreter (basically sugar syntax). In this case b was previously defined and could be called within its self.
local a = function a() end does not work because you just now are defining a and it will error since a is nil to the interpreter
local a = function()
a() --//will error
end
local function b()
b() --//will work
end
But why would you use a = function(), what should you use the different for?
You local function b() if you plan to recursively call a function within its self. you use index = function() when you are likely setting the index within a table. ["Index"] = function() end
Oh ok. Thanks!
Thanks so much!
Sad, I can't up-vote you since I don't have 25 rep :(
Its okay, glad I could help at least :)
They are the same just written differently (as far as I know). I would say doing this:
local function functionNameHere(random)
print("Hi")
end
functionNameHere("Something random")
is better for two reasons.
- Most scripts use that so it may be easier to understand in the long run (from scripts that I look at):
- It has no = sign so it may be faster to write (could not think of anything else).
Both are fine to use from my experiences so whatever you want is good. Hope this helps!
They are different, i'm about to post my answer.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Just answered!
zblox's answer was wrong. There is a difference.