for example
I saw these kinds of scripts
playersfound = {} -- I understand this is a table --But I dont get how a table can be set to to a bool value playersfound[part.Parent.Name] = true playersfound[part.Parent.Name] = part.Parent
I don't understand what these types of things mean
In tables in general, the square brackets []
are used to index a table, it can be used to get and set the value attached to that index of the table
In dictionaries, square brackets are primarily used as an alternative for .
when the key string contains a whitespace, such as "Hello World"
, or "Grape Juice"
.
For example:
local tbl = {} tbl["Hello World"] = "hello there" --(sets the value attached to index) print(tbl["Hello World"]) --hello there (gets the value attached to the index)
On the topic of roblox objects, I believe i explained it in enough detail in my answer on this question, so you should check that out for a more in depth explanation than i will be giving here.
But , in essense the square brackets , when used on objects such as a baseplate, workspace, etc. essentially get one of the properties / children / methods of said object's metatable.
You may be confused on what I mean "the object's metatable" Well, as roblox objects are all userdata values, they are attached to a metatable containing all the children, methods, and properties.
If any of that sound familar, it is because the newproxy
function, when given a true parameter, returns a userdata attached to an empty metatable. newproxy is also handy for things like metatable wrapping
Hopefully this helped!
As Feahren highlighted in his comment, it is the index of a dictionary.
In Lua a table can be treated as an array (a list of values) or a dictionary (a list of keys and values).
Lets define part.Parent.Name
as abc
In your case you have a table: playersFound
.
The following lines say this:
Take the entry (or key) abc
in the table playersFound
and set it's value (which can be anything!) to be 'true'.
The next line is fairly similar:
Take the entry (or key) abc
in the table playersFound
and set it's value to an Object (in this case part.Parent), and we can change the value from a boolean (like true or false) to an Object because a key in a dictionary can have any kind of value.
For more information and examples see: Tables