|
| 14 Aug 2013 12:35 PM |
Like I know that tables are like so:
table = {"blah", "blahdos", "blahdittoditto"}
but can there be subtables?
table = { subtable{"1", "2", "3"}, subtable2{"uno", "dos", "tres"}, subtable3{"a", "b", "c"} }
Yes? No?
If there are subtables? how do I string them?
A normal table would be like table[2], and it would return blahdos
how would I do this for a subtable, if they can be done that way. |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 14 Aug 2013 12:36 PM |
print(table[2]subtable[3] )
would print tres. |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 14 Aug 2013 12:37 PM |
Oops i mean
print(table[2][3])
*derp* |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 14 Aug 2013 12:38 PM |
You can put anything you want in a table, really.
table = { ["subtable"] = {"Hello ", "World!"}, -- One way (setting a string key with []'s and quotes) {"Goodbye ", "Cruel ", "World!"}, -- Another way (setting with a default # key) subtable2 = {"Hi ", "Again ", "World!"}, -- Third way (setting a string key without quotes) }
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 12:38 PM |
Do you mean like this:
temas = { {"Navy blue","Bright green"}; {"Really red","Bright yellow"}; };
for i=1,#teams do print(teams[i][1] .. " is with " .. teams[i][2] .. "!") wait() end
?
- Bigbucks |
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 12:38 PM |
You'd need to set them up like this:
Table = { ["subtable"] = {"1", "2", "3"}, ["subtable2"] = {"uno", "dos", "tres"}, ["subtable3"] = {"a", "b", "c"} }
To print 'dos' you'd need to access it like this:
print(Table["subtable2"][2])
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]- |
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 12:42 PM |
What if the tables have different names? Is there a way to call the table from a StringValue?
Such if there are 6 subtables, and they are named for elements Fire, Water, Earth, Nature, Light, Darkness. If a StringValue has a value of Fire, can the subtable be called by this?
print(table[StringValue.Value]) |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 14 Aug 2013 12:57 PM |
table = { Fire = {stuff} }
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 01:03 PM |
yes but that doesnt answer my question
Elements = { Fire = {"", ""}, Water = {"", ""}, Earth = {"", ""}, Nature = {"", ""}, Light = {"", ""}, Darkness = {"", ""} }
StringValue.Value = Fire
if i call for Elements[StringValue.Value], will it return Fire? Or do tables have to be called by number? |
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 01:03 PM |
tab = { a = { a1 = { a1a = {1, 2, 3}; a1b = {1, 2, 3}; }; a2 = { a2a = {1, 2, 3}; a2b = {1, 2, 3}; }; }; b = { b1 = { b1a = {1, 2, 3}; b1b = {1, 2, 3}; }; b2 = { b2a = {1, 2, 3}; b2b = {1, 2, 3}; }; }; };
--Have some tables in your tables in your tables! |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 14 Aug 2013 01:08 PM |
Tables operate using key, value pairs (sometimes called index, value pairs) The 'key' can be a number of things, including a string. When you say table[something] That 'somthing' is actually just the key in the table - you're looking up the value So if you had a table like table = { Fire = {"Hello", " World!"} -- Using strings without quotes for setting a key is allowed } Then yes, you can say print(table["Fire"][1] .. table["Fire"][2]) Hope that answers your question
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
|
| 14 Aug 2013 01:12 PM |
| So you're saying the answer is yes. If I call for the StringValue's value, and the value is Fire, it will call for the Fire subtable? |
|
|
| Report Abuse |
|
|