When would be the right time to use tables? How would you apply it and also, how does it vairy from Variables.
A table has lots of uses, and with lots I mean a real lot. A cool technical note is that the only data type in Lua actually is a table. Numbers and strings are actually tables, yet you can just use them like they were numbers and strings.
Tables can be used when:
A normal variable is normally a "number" (such as 6 or 3.1) or a "string" (such as "Hello!" and "ugh"). A table is a list. You create tables either list-style or record-style:
-- list style Seasons = {"Winter", "Spring", "Summer", "Autumn"} -- record style PlayerList = { Banned = {jobro13 = true, ConnorVIII = false}, GiveSword = {ConnorVIII = true} }
As you can see you can also put tables inside tables!
To get a field from a table use .
for "keys" (the place in the table where they are stored at) which dont have spaces or special characters or []
for keys which have spaces or special characters.
In fact, "game" is also a "table-like" object. If you use the type function on it, it will return "userdata". Roblox (and actually, Lua) uses C as backend language - it's programmed in there. Lua basically runs in C. Userdata is data from C, but which we can edit from Lua. This is quite special.
-- example: get the "spring" field: Season = Seasons[2] -- Return the "second" field in the list, note: Seasons.2 gives a syntax error. -- example, return if jobro13 is banned: jobro13Banned = PlayerList.Banned.jobro13 -- OR - exactly the same as above: jobro13Banned = PlayerList["Banned"]["jobro13"]
A table is good to use when you have to store multiple variables. Variables can only store one value, but a table can store infinite(I may be wrong here). To make a table simply type: tableName = {"variableOne",2,true} a table can store any type of value you wish to keep track of. To reference a part of a table type: tableName[1] and that will get you the first item, in this case: "variableOne". If you would like to learn more about tables, please visit the wiki: http://wiki.roblox.com/index.php?title=Table I hope this helps.
Locked by adark and Articulating
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?