Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Whats the difference between these two?

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()

2 comments

0

Just answered!

0

zblox's answer was wrong. There is a difference.

2 answers

✓ Accepted answer

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

6 comments

0

But why would you use a = function(), what should you use the different for?

0

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

0

Oh ok. Thanks!

0

Thanks so much!

0

Sad, I can't up-vote you since I don't have 25 rep :(

0

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.

  1. Most scripts use that so it may be easier to understand in the long run (from scripts that I look at):
  2. 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!

1 comment

0

They are different, i'm about to post my answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.