Test = {
T1 = {
X = 1
Y = 1
}
}
print(Test[T1[X]])
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Is it possible to do this?
Started by Micheal Pearce, 14 April 2013 - 07:31 PMPosted 14 April 2013 - 09:31 PM
is it possible to doing a code like this and have it print what X is = to?
Posted 14 April 2013 - 09:33 PM
Yes but a better format is:
You can even do this:
test = {
T1 = {
X = 1,
Y = 2
}
}
print(test.T1.X) -- Returns 2
You can even do this:
test = {
[1] = {
text = {
val1 = "Some"
}
}
}
print(test[1].text.val1) -- returns "Some"
Posted 14 April 2013 - 09:44 PM
Thanks Man/Girl/Demon Baby
Posted 14 April 2013 - 09:48 PM
Hmm I think it's a dogThanks Man/Girl/Demon Baby
On topic:
If you want to iterate trough the values thus might come in hand
for identifier, value in pairs(table) do
print(tostring(identifier).." contains:"..tostring(value))
end
Posted 15 April 2013 - 07:54 AM
Doing tostring(var) when printing isn't necessary, it will do it automatically for you.
Posted 15 April 2013 - 10:35 AM
Doing tostring(var) when printing isn't necessary, it will do it automatically for you.
You can only concatenate a string with a string (or a table with __concat metamethod)
Posted 21 April 2013 - 01:17 AM
Doing tostring(var) when printing isn't necessary, it will do it automatically for you.
You can only concatenate a string with a string (or a table with __concat metamethod)
thats not true you can concatenate string and number without tostring. see Example:
a = 1
d = "1"
c = {1,"1"}
print("Number: " .. a)
print("String: " .. d)
print("both from a table " ..c[1]..c[2])
Posted 21 April 2013 - 01:31 AM
that is because strings and numbers have __concat defined, booleans, tables and some others do not.thats not true you can concatenate string and number without tostring. see Example:
-snip-