#Important question
1 messages · Page 1 of 1 (latest)
Examples:
getting a certain spot in a table
local example = {"A", "B", "C"}
example[1] -- returns A
example[2] -- returns B
finding a child of an instance with a variable
local instance = script.Parent
local instance2 = instance[variable] -- looks for an instance with the same name as the variable, if found returns the instance else returns nil
they can be used in tables to get info by putting in a variable
local profit = {
["Jake"] = "5$"
["Bella"] = "10$"
}
local money = profit["Jake"] -- returns 5%
with [] you can index tables. its incredibly helpful. example above explains it perfectly
Another useful feature with [] is you can index properties of an Instance.
Let's say u make a Utility module about properties or Instances:
function Utils.setProperty(instance: Instance, property: string, value: any)
instance[property] = value
end
i didn't know that :O
i havent needed it ig
You learn something new everyday
only thing is, if you are in !strict mode, the linter may be annoying about it. to fix it, just do this:
(instance :: any)[property] = value