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

Is it possible to get variable name from table

Started by Waterspark63, 11 December 2018 - 06:33 PM
Waterspark63 #1
Posted 11 December 2018 - 07:33 PM
I think its a bit of a stupid question, but is it possible to do something like this?

local names = {"file1","file2",}
local files = {"/file1.lua","/file2.lua"}
for i=1,2 do
	local file = fs.open(folders[i],"r")
	local names[i] = textutils.unserialize(file.readAll())
	file.close()
end
print(names[1])
Edited on 11 December 2018 - 06:34 PM
Lupus590 #2
Posted 11 December 2018 - 08:21 PM
that code looks mine to me. I'm assuming that the contents of the names table in you example is what would be put into it from the tables.
Waterspark63 #3
Posted 11 December 2018 - 11:02 PM
that code looks mine to me. I'm assuming that the contents of the names table in you example is what would be put into it from the tables.

Well, when I run it, I get the error: {[string "testing.lua"]:5: unexpected symbol}
I think its the names part thats erroring…
KingofGamesYami #4
Posted 12 December 2018 - 05:36 AM
You can't make a table entry local. The table itself sets the scope for entries.
Lupus590 #5
Posted 12 December 2018 - 06:36 PM
Opps, I missed the extra local. I evendently have not done enough lua recently.
Edited on 12 December 2018 - 05:36 PM