This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
libraryaddict's profile picture

Return table n, at table[q]

Started by libraryaddict, 25 April 2012 - 08:59 PM
libraryaddict #1
Posted 25 April 2012 - 10:59 PM
A piece of code wants to know if there is anything at table 4, row 14, And there is! But I cant call on it..
if Data4[14] then return Data4[14] end
Thats what I want the program to see

Closest I can get to that is

function checkData(y, x)
  local temp = "Data"..y.."["..x.."]"
  if temp then
	return temp
  else
	return false
  end
end
Data3 = {}
Data3[5] = "hello"
if checkData(3, 5) then
  print(checkData(3, 5))
end

Ofc its churning out Data3[5] not "hello"
So how do I churn out "hello"?
MysticT #2
Posted 25 April 2012 - 11:21 PM
You can try with loadstring, but I don't think it will work.
I think the best way would be to have a Data table, wich has tables inside. Something like this:

local Data = {}
Data[3] = {}
Data[3][5] = "hello"
print(Data[3][5])
libraryaddict #3
Posted 25 April 2012 - 11:34 PM
I think I agree with you MysticT.

It didn't even occur to me to try it that way.