A method is a function member of a class that can be called on an instance, representing a method in object-oriented programming. Methods are expected to be called using a colon (:
) instead of a period (.
), although methods can be called using the period with the first parameter expected as an instance.
Usage
This code will instantiate Part and calls its method IsA, which is an Instance method, passing the class name BasePart as a string. Then, it will print the result as true because its class Part is a subclass of BasePart.
local part = Instance.new("Part") print(part:IsA("BasePart")) -- true
There are a few cases where a dot is used instead, for example:
local destroy = game.Destroy -- this function can be used instead of calling the Destroy method on an instance, since it accepts one of any instance. destroy(workspace.Part) -- destroys a part in the workspace.
Programming |
| ||||||
---|---|---|---|---|---|---|---|
Design | |||||||
Assets | |||||||
Tools | |||||||
Monetization | |||||||
Analytics | Developer Stats · Monthly active users (MAU) | ||||||
Advertising | |||||||
Resources |