New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 8 days ago
local Hi = {}

function Hi.Destroy()
----
end

or also

local Hi = {}

function Hi:ChangeValueToInfinite()
----
end

1 answer

Log in to vote
1
Answered by
Arsubia12 385 Moderation Voter
8 days ago

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

0
You forgot metamethods Feahren 1746 — 8d
0
@Fearhren this kinda tells all that.. Metamethods are declared just like other method, with underscores prefixing Arsubia12 385 — 8d
0
Not at all Feahren 1746 — 8d
0
@Fearhren you can define a metamethod like this: function MetaTable.__MetaMethod() Arsubia12 385 — 4d
Ad

Answer this question