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

what is the point of using table on functions? like this

local Hi = {}

function Hi.Destroy()
----
end

or also

local Hi = {}

function Hi:ChangeValueToInfinite()
----
end

1 answer

✓ Accepted answer

doing:

local car = {
	start = function()
		print("starting car")
	end,

	
	move = function()
		print("moving at 20 MPH")
	end
}

is equivalent to doing:

local car = {}

function car.start()
	print("starting car")
end

function car.move()
	print("moving at 20 MPH")
end

so basically doing that is another way of defining a method of an object (or as you might call it a table in Lua)..

you can do object.X = Y;where X is a property name, and Y is the value of the property, but if you really think about it, there isn't the same syntax for methods without using function object.methodName().. which would only limit you to do:

object = {methodName = f()} or

object.methodName = f()

4 comments

0

You forgot metamethods

0

@Fearhren this kinda tells all that.. Metamethods are declared just like other method, with underscores prefixing

0

Not at all

0

@Fearhren you can define a metamethod like this: function MetaTable.__MetaMethod()

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