I have seen all kinds of brackets these : {} I think are for tables these () I think are for parameters . BUT THESE [] I cannot understand. I don’t get what [] bracket do.
A lot of times it's used to get certain stuff out of tables or dictionary's, but it can also be used to find a child inside of Workspace or another place, It can find children with spaces
Dictionary example: (Tables and Dictionary's are almost the same}
01 | -- Make the dictionary using the [] brackets to name them! |
02 | local fruitDictionary = { |
03 | [ "Bananas" ] = "Not my favorite" ; |
04 | [ "Apples" ] = "Pretty good" ; |
05 | [ "Eggplants" ] = "Sus" ; |
06 | } |
07 |
08 | -- Print the Eggplants |
09 | print (fruitDictionary [ "Eggplants" ] ) |
10 | -- When you run the script it should say sus! |
Children Example
1 | workspace [ "My Part that has a space" ] .BrickColor = BrickColor.new( "Bright green" ) |
Hope this answered your question!
Square brackets are used to reference items in a table. For example:
1 | local table = { 12 , 41 , 62 } |
2 |
3 | print (table [ 2 ] ) --prints 41 |
4 |
5 | table [ 2 ] = 123 |
6 |
7 | print (table [ 2 ] ) --prints 123 |
8 |
9 | print (table [ 1 ] ) --prints 12 |
They can also be used to reference table keys that are strings:
1 | local table = { |
2 | [ "oranges" ] = 152 , |
3 | [ "apples" ] = 127 , |
4 | [ "potatoes" ] = 4 |
5 | } |
6 |
7 | print (table [ "apples" ] ) --prints 127 |
Square brackets can be used to find things you may not be able to without using them. another use is for picking a certain item in a table
1 | part = workspace.my part -- This will not work |
2 | part = workspace [ "my part" ] -- this will work |
3 |
4 | mytable = { one, two, three } |
5 |
6 | mytable [ 2 ] = "seven" |
I hope this makes sense
hey you! have you ever heard of enes? if you are in trouble, better call enes!