Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

What does it mean when there is variable[something]?

Asked by 7 years ago

Hello, What does it mean when a variable is defined and in the next line the scripter says variable[something]? Thanks! I know it sounds basic, but I've seen it very often and believe it must be important.

1
It means variable is a table. GoldenPhysics 474 — 7y
1
Brackets index a table, so if you have t={'a','b','c','d','e'}, t[3] is 'c' 1waffle1 2908 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

Whenever you use brackets, you're grabbing something from a table.

In example

lottery = ['15','22','35','47','52']
print(lottery[2])
--If this example is correct, it will print out the second thing listed in the table, so in the case, it'll print the number 22.
Ad

Answer this question