Jump to content




Is it possible to get variable name from table


  • You cannot reply to this topic
4 replies to this topic

#1 Waterspark63

  • Members
  • 13 posts

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 by Waterspark63, 11 December 2018 - 07:34 PM.


#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

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.

#3 Waterspark63

  • Members
  • 13 posts

Posted 11 December 2018 - 11:02 PM

View PostLupus590, on 11 December 2018 - 08:21 PM, said:

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[i] part thats erroring...

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 12 December 2018 - 05:36 AM

You can't make a table entry local. The table itself sets the scope for entries.

#5 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 12 December 2018 - 06:36 PM

Opps, I missed the extra local. I evendently have not done enough lua recently.

Edited by Lupus590, 12 December 2018 - 06:36 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users